-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: MaxDB, Problem beim Einfügen neuer Datensätze
PostPosted: Fri Nov 30, 2007 5:04 am 
Newbie

Joined: Fri Nov 30, 2007 4:17 am
Posts: 2
Hibernate version: 3.2.5


Hallo,

hat jemand Erfahrung mit der MAXDB/SAPDB in Verbindung mit Hibernate ?
Mein Problem ist, dass ich keine Datensätze in Tabellen einfügen kann, die den Typ SERIAL in der Key-Spalte benutzen. Dabei handelt es sich um sowas wie auto_increment bei MySQL.

@GeneratedValue(strategy=GenerationType.AUTO) resultiert in einer Exception:


SCHWERWIEGEND: [-4020] (at 8): Unknown sequence name:HIBERNATE_SEQUENCE
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not get next sequence value
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:237)
at dbtest.Main.test(Main.java:376)
at dbtest.Main.main(Main.java:582)
Caused by: org.hibernate.exception.GenericJDBCException: could not get next sequence value
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:96)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:99)
at org.hibernate.ejb.event.EJB3MergeEventListener.saveWithGeneratedId(EJB3MergeEventListener.java:43)
at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:186)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:123)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665)
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:228)
... 2 more
Caused by: com.sap.dbtech.jdbc.exceptions.DatabaseException: [-4020] (at 8): Unknown sequence name:HIBERNATE_SEQUENCE
at com.sap.dbtech.jdbc.packet.ReplyPacket.createException(ReplyPacket.java:72)
at com.sap.dbtech.jdbc.ConnectionSapDB.throwSQLError(ConnectionSapDB.java:946)
at com.sap.dbtech.jdbc.ConnectionSapDB.execute(ConnectionSapDB.java:584)
at com.sap.dbtech.jdbc.CallableStatementSapDB.sendCommand(CallableStatementSapDB.java:1797)
at com.sap.dbtech.jdbc.StatementSapDB.sendSQL(StatementSapDB.java:866)
at com.sap.dbtech.jdbc.CallableStatementSapDB.doParse(CallableStatementSapDB.java:242)
at com.sap.dbtech.jdbc.CallableStatementSapDB.constructor(CallableStatementSapDB.java:195)
at com.sap.dbtech.jdbc.CallableStatementSapDB.<init>(CallableStatementSapDB.java:88)
at com.sap.dbtech.jdbc.ConnectionSapDB.prepareStatement(ConnectionSapDB.java:835)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
at org.hibernate.jdbc.AbstractBatcher.prepareSelectStatement(AbstractBatcher.java:123)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:73)
... 11 more


Ich sehe, dass Hibernate diese Query erzeugt hat:

Hibernate: select hibernate_sequence.nextval from dual

was leider so nicht funktionieren kann, weil es sogesehen keine Sequence gibt. Man kann lediglich per "select tabellenname.currval from dual" die letzte erzeugte ID abfragen.
Hat jemand evtl. eine Lösung für das Problem ?

danke und Gruß


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 30, 2007 3:44 pm 
Newbie

Joined: Fri Nov 30, 2007 4:17 am
Posts: 2
Hab das Problem gelöst. Habe die Klasse SAPDBDialect soweit abgeändert, dass jetzt Primärschlüssel vom Typ SERIAL richtig behandelt werden @GeneratedValue(strategy = GenerationType.IDENTITY). Falls jemand Interesse daran, der braucht nur folgende 3 Funktionen in die Klasse SAPDBDialect einzufügen:


Code:
public boolean supportsIdentityColumns() {
   return true;
}

public String getIdentitySelectString(String table, String column, int type) {
   return "select "+table+".currval from dual";
}

public String getIdentityColumnString() {
   return "not null default serial";
}




Gruß
nero


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.