Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate/Spring

 
vijaya sharma
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using hibernate 3.0 and spring 1.2.4

When i try to instantiate the Class object using the test(which uses JUnit) with out performing any inserts( just trying to extract the column value)

I get the following Error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SomeNameObjectSessionFactory' defined in class path resource [some-manualtest-test.xml]: Initialization of bean failed; nested exception is org.hibernate.MappingException: could not instantiate id generator

org.hibernate.MappingException: could not instantiate id generator

I wonder why it should not be able to generate the id,The id generator code extracted from the HBM file is as follows:

<id name="Id" type="long" column="some_id">
<generator class="sequence">
<param name="sequence">some_id_seq</param>
</generator>
</id>

I would be greatly thankful if someone could tell me if there is something wrong, with respect to maybe incompatible versions of hibernate and spring or am i missing something.

Thanks,
Vijay
 
Michael Duffy
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vijayasharm sharma:
I am using hibernate 3.0 and spring 1.2.4

When i try to instantiate the Class object using the test(which uses JUnit) with out performing any inserts( just trying to extract the column value)

I get the following Error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SomeNameObjectSessionFactory' defined in class path resource [some-manualtest-test.xml]: Initialization of bean failed; nested exception is org.hibernate.MappingException: could not instantiate id generator

org.hibernate.MappingException: could not instantiate id generator

I wonder why it should not be able to generate the id,The id generator code extracted from the HBM file is as follows:

<id name="Id" type="long" column="some_id">
<generator class="sequence">
<param name="sequence">some_id_seq</param>
</generator>
</id>

I would be greatly thankful if someone could tell me if there is something wrong, with respect to maybe incompatible versions of hibernate and spring or am i missing something.

Thanks,
Vijay


Yes, you're missing something.

Spring and Hibernate are telling you that the database dialect you're using does not support sequences. You didn't say which database you're using, but if it's SQL server the generator class should be "identity". The safest choice would be "native" - let Hibernate decide based on the database.
 
vijaya sharma
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for the reply
I am using spring-xml file where i have configured the dilect property

<bean id="boatsSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="boatsDataSource"/>
</property>

<property name="mappingDirectoryLocations">
<list>
<value></value>
</list>
</property>

<property name="hibernateProperties">
<props>
(See This Line)
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
</props>
</property>
</bean>


As you suggested that i should let hibernate decide, I tried using the native but it didn't work as well.

Do you think there could be somethis else to it.

Thanks in advance.
 
anuja Edathu
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi vijayasharm ,
Try this if you are using Oracleadatabase, this should work . It works for me

<id name="Id" column="some_id" >

<generator class="increment"/>
</id>
Regards,

Anuja Karthikeyan
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be able to use sequences with Oracle. Check to see if the Oracle account you are accessing the database with has permission to create/access that sequence -- perhaps that is why it is failing.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, be careful if you use "increment". Quoting from Hibernate in Action:
The generator [increment] is especially efficient if the single-server Hibernate application has exclusive access to the database but shouldn't be used in any other scenario.

[ January 11, 2006: Message edited by: Jeff Albrechtsen ]
 
vijaya sharma
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeff,Anuja and michael. Identity as the document says works.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic