ho fatto un esperimento ... un soggetto comune per i repository di Data due Primavera: - JPA - MongoDBDati di primavera mongodb. Generazione di errore di id
prima di tutto' utilizzando seguenti librerie versioni:
primavera-dati- JPA: 1.7.0.RELEASE primavera-dati-mongodb: 1.6.0.RELEASE
ho un Entity:
@Entity
@Table(name = "ACCOUNTS")
public class Account {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ACCOUNT_ID")
private Long id;
@Column(name = "ACCOUNT_NUMBER")
private String number;
public Account() {
}
public Account(String number) {
this.number = number;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
}
JPA Repos itory ha seguente aspetto:
public interface Repository extends CrudRepository<Account, Long> {
public Account findByNumber(String number);
}
MongoDB repository ha seguente aspetto:
pacchetto ua.home.springdata.investigation.repository.mongo;
public interface Repository extends CrudRepository<Account, Long> {
}
Quindi ... APP funziona :) :) Niente di speciale Ma prova MongoDB non è passato :( sto ottenendo un errore:
org.springframework.dao.InvalidDataAccessApiUsageException: Cannot autogenerate id of type java.lang.Long for entity of type ua.home.springdata.investigation.entity.Account! at org.springframework.data.mongodb.core.MongoTemplate.assertUpdateableIdIfNotSet(MongoTemplate.java:1149) at org.springframework.data.mongodb.core.MongoTemplate.doSave(MongoTemplate.java:878) at org.springframework.data.mongodb.core.MongoTemplate.save(MongoTemplate.java:833) at org.springframework.data.mongodb.repository.support.SimpleMongoRepository.save(SimpleMongoRepository.java:73) at org.springframework.data.mongodb.repository.support.SimpleMongoRepository.save(SimpleMongoRepository.java:88) at org.springframework.data.mongodb.repository.support.SimpleMongoRepository.save(SimpleMongoRepository.java:45) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:442) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:427) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:381) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) at com.sun.proxy.$Proxy26.save(Unknown Source)
Penso che sia un caso molto comune . Perché non è la primavera dei dati in grado di generare l'ID entità come a lungo? E 'così strano.
Quando sto aggiungendo l'annotazione ** @ GeneratedValue ** mio IDE sta lanciando un errore allora e là. Ho usato la dipendenza ** jpa ** nel mio file 'pom.xml', ma anche quello non funziona come quello che ho ottenuto è che cerca un DB MySQL e sto usando NoSQL (mongoDB). Quindi se puoi aiutarmi con qualcosa per favore fallo. Grazie in anticipo. – Learner
@Neil Stockton Quando aggiungo l'annotazione ** @ GeneratedValue ** il mio IDE lancia un errore allora e là. Ho usato la dipendenza ** jpa ** nel mio file 'pom.xml', ma anche quello non funziona come quello che ho ottenuto è che cerca un DB MySQL e sto usando NoSQL (mongoDB). Quindi se puoi aiutarmi con qualcosa per favore fallo. Grazie in anticipo .. – Learner