-->
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.  [ 5 posts ] 
Author Message
 Post subject: Mapping files with sequence-names
PostPosted: Sat Jun 02, 2007 9:23 am 
Regular
Regular

Joined: Wed Nov 01, 2006 2:17 pm
Posts: 78
Hello,

how do I generate hbm.xml-Mapping files that use Oracle sequences following the pattern "entityname_id_seq"?

The underlying databasse schema is changing from time to time so it is quite exhausting to edit the reveng.xml file and provide the correct sequence-names for each entity every time.

Is it possible to provide the hbm2hbmxml-tag a pattern to generate the sequence-names in the mapping files?

Thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 02, 2007 10:03 am 
Regular
Regular

Joined: Wed Nov 01, 2006 2:17 pm
Posts: 78
I assume I will have to use my own customized strategy to adapt the primary key definitions to have a "generated by sequence"-attribute.

Which method do I have to override to have a sequence in my hbm.xmls at last?

Code:
public class OracleReverseEngineeringStrategy extends DelegatingReverseEngineeringStrategy
   implements ReverseEngineeringStrategy {

   public OracleReverseEngineeringStrategy(ReverseEngineeringStrategy strategy) {
      super(strategy);
   }

.....
// which method(s)
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 02, 2007 10:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
public String getTableIdentifierStrategyName(TableIdentifier identifier);

public Properties getTableIdentifierProperties(TableIdentifier identifier);

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 03, 2007 1:04 pm 
Regular
Regular

Joined: Wed Nov 01, 2006 2:17 pm
Posts: 78
I did only override getTableIdentifierStrategyName to return "native":

Code:
   public OracleReverseEngineeringStrategy(ReverseEngineeringStrategy strategy) {
      super(strategy);
   }
   
   @Override
   public String getTableIdentifierStrategyName(TableIdentifier arg0) {
      return "native";
   }


While trying to persist an object with Hibernate, I get an exception saying that the sequence does not exist!

Code:
2007-06-03 18:52:08,495 [main] WARN  org.hibernate.util.JDBCExceptionReporter - SQL Error: 2289, SQLState: 42000
2007-06-03 18:52:08,495 [main] ERROR org.hibernate.util.JDBCExceptionReporter - ORA-02289: Sequence ist nicht vorhanden.

Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not get next sequence value
   at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
   at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
   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:85)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:96)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
   at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:468)
   at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:463)
   at org.myorg.myapp.persistence.hibernate.dao.MyEntityDaoImpl.makePersistent(MyEntityDaoImpl.java:43)
   at org.myorg.myapp.persistence.hibernate.dao.MyEntityDaoImpl.makePersistent(MyEntityDaoImpl.java:1)
   at org.myorg.myapp.persistence.hibernate.manager.MyEntityManagerImpl.makePersistent(MyEntityManagerImpl.java:41)
   at org.myorg.myapp.persistence.test.Test.main(Test.java:19)
Caused by: java.sql.SQLException: ORA-02289: Sequence ist nicht vorhanden.

   at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
   at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
   at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
   at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
   at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
   at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:799)
   at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1039)
   at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:839)
   at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1132)
   at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
   at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3329)
   at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:75)
   ... 11 more
.....
.....
2007-06-03 19:03:26,770 [main] DEBUG org.hibernate.util.JDBCExceptionReporter - could not get next sequence value [select hibernate_sequence.nextval from dual]


Looking into the Oracle database there definitely is a sequence realting to the object I am about to persist.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 03, 2007 5:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you are talking about a sequence per object but are using the default hibernate_sequence name.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.