Announcement Announcement Module
Collapse
No announcement yet.
Problem with code generated for 'char' column for openjpa Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with code generated for 'char' column for openjpa

    After reverse engineering the following table:
    Code:
        <table name="problem">
            <column name="Transaction_ID" primaryKey="false" required="true" scale="0" size="20" type="-5,BIGINT UNSIGNED"/>
            <column name="User_ID" primaryKey="false" required="true" scale="0" size="10" type="1,CHAR"/>
            <column name="Cart_ID" primaryKey="false" required="true" scale="0" size="10" type="1,CHAR"/>
            <column name="Relay_Type" primaryKey="false" required="true" scale="0" size="1" type="1,CHAR"/>
            <column name="Code" primaryKey="false" required="true" scale="0" size="7" type="4,MEDIUMINT"/>
            <column name="Ordering" primaryKey="false" required="true" scale="0" size="3" type="1,CHAR"/>
            <column name="Detail" primaryKey="false" required="true" scale="0" size="60" type="1,CHAR"/>
            <index name="ndx_power_load">
                <index-column name="Transaction_ID"/>
                <index-column name="User_ID"/>
                <index-column name="Cart_ID"/>
            </index>
            <index name="ndx_load_id">
                <index-column name="Transaction_ID"/>
                <index-column name="Cart_ID"/>
            </index>
        </table>
    I get the following error when performing the tests:

    Code:
    org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is <openjpa-2.1.0-r422266:1071316 fatal user error> org.apache.openjpa.persistence.ArgumentException: "my.test.domain.Problem.id.my.test.domain.ProblemPK.relayType" declares a column that is not compatible with the expected type "integer".  Column details:
    Full Name: problem.Relay_Type
    Type: char
    Size: 1
    Default: S
    Not Null: true
    
    	at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:382)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
    	at org.springframework.test.context.transaction.TransactionalTestExecutionListener$TransactionContext.startTransaction(TransactionalTestExecutionListener.java:507)
    	at org.springframework.test.context.transaction.TransactionalTestExecutionListener.startNewTransaction(TransactionalTestExecutionListener.java:269)
    	at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethod(TransactionalTestExecutionListener.java:162)
    	at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:358)
    	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73)
    	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:115)
    	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:150)
    	at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91)
    	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
    I'm new to Roo and and Spring JPA development, and I don't see how to get around this issue.

  • #2
    Try using the --includeNonPortableAttributes option on the database reverse engineer command.
    Last edited by Alan Stewart; May 19th, 2011, 06:41 PM.

    Comment


    • #3
      I get the same result running the test, after generating with the --includeNonPortableAttributes.

      Comment


      • #4
        I also tried hibernate with and without the includeNonPortableAttributes and got a different problem. The following code was generated:

        Code:
            public static long Problem.countProblems() {
                return entityManager().createQuery("SELECT COUNT(o) FROM Problem o", Long.class).getSingleResult();
            }
        That query is not valid so the test fails.

        Comment


        • #5
          Apparently openjpa stores CHARs as numbers by default. I got around is issue by adding:
          Code:
          <property name="openjpa.jdbc.DBDictionary" value="storeCharsAsNumbers=false"/>
          to persistence.xml.

          Comment

          Working...
          X