• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Hibernate-Oracle Sequence...

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have created a oracle sequence(hibernate_seq) with start value 100.
And I have the below mapping in my .hbm.xml file to get the next sequence
value.

When I test using JUnit, I get the applicationId=1 where I would expect
applicationId to be 100 which is the current sequence value.

When I execute teh Junit test script 3 times, instead of creating 3 records,
the same record is overridden and the applicationId has the value 1.

Please let me know if I am doing some thing wrong?

<id name="applicationId" column="APPLICATION_ID" type="long" unsaved-
value="0">
<generator class="sequence">
<param name="sequence">hibernate_seq</param>
</generator>
</id>
 
Konda Golamaru
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the below JUnit test method.
When I execute the command: ant test -Dtestcase=ApplicationDAO, How come only one record being created in the database table though
I execute the command more than one time. Each time the applicationId is set to : 1.

Does not it create a record for each execution? Please help.

public void testSaveApplication() throws Exception{
//Configuration configuration = new Configuration(); // configuring hibernate
SessionFactory sessionFactory = (SessionFactory)ctx.getBean("sessionFactory") ;

Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();

application=new Application();
application.setApplicationNumber("123");
application.setApplicationTitle("test_title");
application.setApplicationTypeId("8");
application.setMarketedName("marketed name");
application.setRenewalCycle("renewal cycle");
application.setComments("comments");
application.setInitialSubmissionId("12345678");
application.setAssociateApplicationId("81");
application.setLockedBy("Locked By");
application.setCreatedBy("spring");
application.setCreatedOn("31-JULY-2008");
application.setLastModifiedBy("spring");
application.setLastModifiedOn("31-JULY-2008");
application.setProcedureId("1");
application.setAtcCode("811");
application.setFilingAgencyId("4");
application.setParentNationalApplicationId("5");
application.setInitialApplicationSubTypeId("6");
application.setLockedBySessionId("Lock by session id");
application.setAppMedicinalProducts("6 mg");
application.setAssociateApplicationId("9");
application.setPlannedSubmissionsCount("5");
application.setActualSubmissionsCount("6");


dao.saveApplication(application);


assertNotNull("primary key assigned",application.getApplicationId());
log.info(application);
assertNotNull(application.getApplicationNumber());

log.debug("end of testSaveApplication");

Application app=dao.getApplication(application.getApplicationId());
log.debug(" app : "+app);

tx.commit();
session.flush();
session.close();
}
 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would you know if you have the hbm ddl property set to create-drop?
 
Konda Golamaru
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

Thanks for your reply.

Please find the below session factory mapping info for the property mapping.
I have the ddl property set to create. Please let me know if you see any issues/errors with the mapping.


<property name="hibernateProperties">
<props>
<prop
key="hibernate.dialect">net.sf.hibernate.dialect.OracleDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
 
Konda Golamaru
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

Finally It works as I expected. I have changed the hbm ddl property value from create to update and it works.

<prop key="hibernate.hbm2ddl.auto">update</prop>


Now, it picks the next sequence value and also It creates the new record for each JUnit execution.

Your reply helped me to dig further on the issue and finally here we are.

Thanks again.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Konda, I have a problem with the Sequences in Oracle, I am not using triggers + sequences in Oracle DB, only sequences, and i have defined my entities using hbm.xml files.

The problem I have is that the sequence doesn't start using the value defined in DB, and when the Application is running It creates records with Id=50, the next time I start the Oracle Server It start records are created using ID=100 and increments.. I really don't figure out, What is the problem ? Do you have any Idea? I have left part of my code here...

The Id's finally are generated and save in db, but I want to have a normal flow... 1,2,3,4,5, N and actually I get.. 50,51,52, restart oracle and Application and then.. 50,51,52,53... other restart more and I get .. 100,101,102,103...

Any Idea ?

regards

Eduardo





And the generated Java Entity is:




Konda Golamaru wrote:Hi Paul,

Finally It works as I expected. I have changed the hbm ddl property value from create to update and it works.

<prop key="hibernate.hbm2ddl.auto">update</prop>


Now, it picks the next sequence value and also It creates the new record for each JUnit execution.

Your reply helped me to dig further on the issue and finally here we are.

Thanks again.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic