Announcement Announcement Module
Collapse
No announcement yet.
Roo + Hibernate Generated Integration Tests Fail Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Roo + Hibernate Generated Integration Tests Fail

    So I've reverse engineered my database and generated source for specific tables. I ironed out most of the problems that arise from running the integration tests except for the case when a table has a composite key.

    For instance, this table
    Code:
    CREATE TABLE `cbt_suggest` (
      `productRoot` int(11) NOT NULL DEFAULT '0',
      `alsoRoot` int(11) NOT NULL DEFAULT '0',
      `count` int(32) DEFAULT NULL,
      `alsoRootDisplayProdId` int(32) DEFAULT NULL,
      PRIMARY KEY (`productRoot`,`alsoRoot`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    I ran the following ROO script
    Code:
    project --topLevelPackage com.soundstrue.ecommerce.persistence --projectName ecommerce-persistence
    persistence setup --provider HIBERNATE --database MYSQL
    database properties set --key database.url --value jdbc:mysql://localhost:3306/konakart?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior\=convertToNull
    database properties set --key database.username --value root
    osgi obr url add --url http://spring-roo-repository.springsource.org/repository.xml
    osgi obr start --bundleSymbolicName org.springframework.roo.wrapping.mysql-connector-java
    database introspect --schema konakart
    database reverse engineer --schema konakart --package ~.konakart --testAutomatically --includeTables "cbt_suggest"
    That generated two sets of objects:

    CbtSuggest.java
    _Roo_Configurable.aj
    _Roo_DbManaged.aj
    _Roo_Entity.aj
    _Roo_ToString.aj

    CbtSuggestPK.java
    _Roo_Configurable.aj
    _Roo_Identifier.aj
    _Roo_Json.aj
    _Roo_Serializable.aj

    And associated test objects:

    CbtSuggestIntegrationTest.java
    _Roo_IntegrationTest.aj
    _Roo_Configurable.aj

    CbtSuggestDataOnDemand.java
    _Roo_DataOnDemand.aj
    _Roo_Configurable.aj

    The CbtSugggestIntegrationTest_Roo_IntegrationTest.aj shows the following as testing persist():
    Code:
    Test
        public void CbtSuggestIntegrationTest.testPersist() {
            org.junit.Assert.assertNotNull("Data on demand for 'CbtSuggest' failed to initialize correctly", dod.getRandomCbtSuggest());
            com.soundstrue.ecommerce.persistence.konakart.CbtSuggest obj = dod.getNewTransientCbtSuggest(Integer.MAX_VALUE);
            org.junit.Assert.assertNotNull("Data on demand for 'CbtSuggest' failed to provide a new transient entity", obj);
            org.junit.Assert.assertNull("Expected 'CbtSuggest' identifier to be null", obj.getId());
            obj.persist();
            obj.flush();
            org.junit.Assert.assertNotNull("Expected 'CbtSuggest' identifier to no longer be null", obj.getId());
        }
    When I build the project with testing enabled, I get the following stack
    Code:
    testPersist(com.soundstrue.ecommerce.persistence.konakart.CbtSuggestIntegrationTest)  Time elapsed: 0.03 sec  <<< ERROR!
    org.springframework.orm.jpa.JpaSystemException: org.hibernate.id.IdentifierGenerationException: null id generated for:class com.soundstrue.ecommerce.persistence.konakart.CbtSuggest; nested exception is javax.persistence.PersistenceException: org.hibernate.id.IdentifierGenerationException: null id generated for:class com.soundstrue.ecommerce.persistence.konakart.CbtSuggest
    	at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:311)
    	at org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect.ajc$afterThrowing$org_springframework_orm_jpa_aspectj_JpaExceptionTranslatorAspect$1$18a1ac9(JpaExceptionTranslatorAspect.aj:15)
    	at com.soundstrue.ecommerce.persistence.konakart.CbtSuggest_Roo_Entity.ajc$interMethod$com_soundstrue_ecommerce_persistence_konakart_CbtSuggest_Roo_Entity$com_soundstrue_ecommerce_persistence_konakart_CbtSuggest$persist(CbtSuggest_Roo_Entity.aj:39)
    	at com.soundstrue.ecommerce.persistence.konakart.CbtSuggest.persist(CbtSuggest.java:1)
    	at com.soundstrue.ecommerce.persistence.konakart.CbtSuggest_Roo_Entity.ajc$interMethodDispatch1$com_soundstrue_ecommerce_persistence_konakart_CbtSuggest_Roo_Entity$com_soundstrue_ecommerce_persistence_konakart_CbtSuggest$persist(CbtSuggest_Roo_Entity.aj)
    	at com.soundstrue.ecommerce.persistence.konakart.CbtSuggestIntegrationTest_Roo_IntegrationTest.ajc$interMethod$com_soundstrue_ecommerce_persistence_konakart_CbtSuggestIntegrationTest_Roo_IntegrationTest$com_soundstrue_ecommerce_persistence_konakart_CbtSuggestIntegrationTest$testPersist(CbtSuggestIntegrationTest_Roo_IntegrationTest.aj:69)
    	at com.soundstrue.ecommerce.persistence.konakart.CbtSuggestIntegrationTest.testPersist(CbtSuggestIntegrationTest.java:1)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
    	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
    	at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:35)
    	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:146)
    	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:97)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
    	at $Proxy0.invoke(Unknown Source)
    	at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:145)
    	at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:87)
    	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
    Caused by: javax.persistence.PersistenceException: org.hibernate.id.IdentifierGenerationException: null id generated for:class com.soundstrue.ecommerce.persistence.konakart.CbtSuggest
    	at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214)
    	at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147)
    	at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1153)
    	at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:678)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
    	at $Proxy36.persist(Unknown Source)
    	... 39 more
    Caused by: org.hibernate.id.IdentifierGenerationException: null id generated for:class com.soundstrue.ecommerce.persistence.konakart.CbtSuggest
    	at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:123)
    	at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:69)
    	at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:179)
    	at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:135)
    	at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
    	at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:808)
    	at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:782)
    	at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:786)
    	at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:672)
    	... 45 more
    What am I missing here? I am pretty new to using Hibernate and Roo. There isn't much out there that can help me figure this out on my own so if anyone has a suggestion I would appreciate it.

    Edit: Forgot to mention that I am using Roo 1.1.2 Release and Hibernate 3.6.1 GA on MySQL 5.1.30
    Last edited by Greuvee; Mar 4th, 2011, 06:05 PM.

  • #2
    Roo integration tests and data on demand do not support composite primary keys yet. If you would like to see this feature, please vote for https://jira.springsource.org/browse/ROO-2070
    Alan

    Comment

    Working...
    X