Ich Oracle-Datenbank verwenden und versuchen, neue Entität in "Wörter" Tabelle hinzufügen. Meine Wortmodellklasse:Java-Ruhezustand konnte ResultSet beim Versuch, Entität
@Entity(name = "Word")
public class Word implements Serializable{
public Long getId() {
return id;
}
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE,
generator = "etailerRaw_seq")
@SequenceGenerator(name = "etailerRaw_seq",
sequenceName = "'PRODUCT_ID_SEQ")
private Long id;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "name")
public String name;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "word")
private Set<Translation> translations;
public Set<Translation> getTranslations(){
return translations;
}
}
Übersetzung Modell Klasse
@Entity(name = "Translation")
public class Translation {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE,
generator = "etailerRaw_seq")
@SequenceGenerator(name = "etailerRaw_seq",
sequenceName = "'PRODUCT_ID_SEQ")
private Long id;
public Long getId() {
return id;
}
public Word getWord() {
return word;
}
public Language getLanguage() {
return language;
}
public void setWord(Word word) {
this.word = word;
}
public void setLanguage(Language language) {
this.language = language;
}
public String getNameTranslation() {
return nameTranslation;
}
public void setNameTranslation(String nameTranslation) {
this.nameTranslation = nameTranslation;
}
public String getDescriptionTranslation() {
return descriptionTranslation;
}
public void setDescriptionTranslation(String descriptionTranslation) {
this.descriptionTranslation = descriptionTranslation;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "Word_id", nullable = false)
private Word word;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "Lang_id", nullable = false)
private Language language;
private String nameTranslation;
private String descriptionTranslation;
}
Sprachmodellklasse
@Entity(name = "Language")
public class Language implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE,
generator = "etailerRaw_seq")
@SequenceGenerator(name = "etailerRaw_seq",
sequenceName = "'PRODUCT_ID_SEQ")
private Long id;
@Column(name = "name")
private String name;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "language")
private Set<Translation> translations;
public Set<Translation> getTranslations(){
return translations;
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Wort dao Klasse
public class WordDAOBean implements WordDAO {
public void addWord(String description) {
Word word=new Word();
word.setName(description);
Session session= HibernateUtil.getSession();
session.save(word);
session.close();
}
public List<Word> getAllWords() {
Session session= HibernateUtil.getSession();
List<Word> words= session.createCriteria(Word.class).list();
session.close();
return words;
}
}
getAllWords Methode arbeitet successefu ll, aber wenn ich tryiing neues Wort hinzufügen, bekomme ich
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:80)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:89)
at org.hibernate.id.SequenceGenerator.generateHolder(SequenceGenerator.java:122)
at org.hibernate.id.SequenceHiLoGenerator$1.getNextValue(SequenceHiLoGenerator.java:81)
at org.hibernate.id.enhanced.LegacyHiLoAlgorithmOptimizer.generate(LegacyHiLoAlgorithmOptimizer.java:77)
at org.hibernate.id.SequenceHiLoGenerator.generate(SequenceHiLoGenerator.java:78)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:117)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:209)
at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:194)
at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:711)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:703)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:698)
at DAO.impl.WordDAOBean.addWord(WordDAOBean.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4786)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:656)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:64)
at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52)
at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140)
at sun.reflect.GeneratedMethodAccessor70.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4758)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4746)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
... 33 more
Caused by: java.sql.SQLSyntaxErrorException: ORA-01756: quoted string not properly terminated
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:884)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1167)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1289)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3584)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3628)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1493)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:80)
... 76 more
]]
auf dieser str session.save (Wort);
'sequenceName =" 'PRODUCT_ID_SEQ "'. Beachten Sie das einfache Anführungszeichen am Anfang des Namens der Sequenz. Warum definieren Sie denselben Sequenzgenerator zweimal? Abstimmung zum Schließen für einen einfachen Tippfehler. –