Announcement Announcement Module
Collapse
No announcement yet.
Trouble setting up Spring and JPA w/ Toplink Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trouble setting up Spring and JPA w/ Toplink

    I have been searching these forums and reading all sorts of articles and I have tried just about every option, but I just can't seem to get it right.

    I'm just at the beginning of my application. I've created a bunch of entities and have tried setting up persistence so that the tables are created automatically. I keep getting errors or just none of the tables being created.

    persistence.xml:

    Code:
    <persistence-unit name="GigFoxPU">
            <properties>
                <property name="toplink.logging.level" value="FINE" />
                <property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
                <property name="toplink.jdbc.url" value="jdbc:mysql://localhost:3306/gigfox"/>
                <property name="toplink.jdbc.user" value="user"/>
                <property name="toplink.jdbc.password" value="pass"/>
                <property name="toplink.ddl-generation" value="drop-and-create-tables"/>
            </properties>
        </persistence-unit>
    applicationContext.xml:

    Code:
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <property name="persistenceUnitName" value="GigFoxPU" />
            <property name="loadTimeWeaver">
                <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
            </property>
            <property name="jpaVendorAdapter">
                <bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter">
                    <property name="databasePlatform" value="oracle.toplink.essentials.platform.database.MySQL4Platform"/>
                    <property name="generateDdl" value="true"/>
                    <property name="showSql" value="true"/>
                </bean>
            </property>
        </bean>
        
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
          <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
          <property name="url" value="jdbc:mysql://localhost:3306/gigfox"/>
          <property name="username" value="user"/>
          <property name="password" value="pass"/>
       </bean>
        
        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
            <property name="entityManagerFactory" ref="entityManagerFactory" />
        </bean>
        
        <tx:annotation-driven />
    Sometimes it just doesn't do anything, but when I finally do get it to try to create tables, it gives a syntax error that seems like it has a problem with TINYINT.

    I'm using MySQL5 and Glassfish, and I want to mainly use JPA but with Toplink as the default if I need advanced stuff.

    Please, any help would be great. I get the feeling I am just missing the correct configuration because I've reached the point of just copy and pasting a million different things in to try to get it working.

    Cheers,
    Steph

  • #2
    Ok, I have an update. I think maybe it is a problem with toplink and mysql. My mysql database is version 5.0, and it seems with toplink, the only mysql database property is mysql4. That seems to be what is causing this syntax error:

    java.sql.SQLException: Syntax error: Encountered "" at line 1, column 104

    I think I have everything else ok now.

    persistence.xml:

    Code:
        <persistence-unit name="GigFoxPU">
            <provider>oracle.toplink.essentials.PersistenceProvider</provider>
                <property name="toplink.logging.level" value="FINE" />
                <property name="toplink.target-database" value="MySQL4" />
                <property name="toplink.ddl-generation" value="drop-and-create-tables"/>
            </properties>
        </persistence-unit>
    applicationContext.xml:

    Code:
        <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
    
        <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
        
        <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <property name="persistenceUnitName" value="GigFoxPU" />
            <property name="loadTimeWeaver">
                <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
            </property>
            <property name="jpaVendorAdapter">
                <bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter">
                    <!--property name="databasePlatform" value="oracle.toplink.essentials.platform.database.MySQL4Platform"/-->
                    <property name="generateDdl" value="true"/>
                    <property name="showSql" value="true"/>
                    <property name="database" value="MYSQL"/>
                </bean>
            </property>
        </bean>
        
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
          <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
          <property name="url" value="jdbc:mysql://localhost:3306/gigfox"/>
          <property name="username" value="root"/>
          <property name="password" value="cheetah"/>
       </bean>
        
        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
            <property name="entityManagerFactory" ref="entityManagerFactory" />
        </bean>
        
        <tx:annotation-driven />
    Anyone experience this problem?

    Maybe I'm using a bunch of versions that don't work well together. My toplink version is:

    TopLink, version: Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))

    Cheers,
    Steph

    Comment


    • #3
      I've got

      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.5</version>

      <groupId>toplink.essentials</groupId>
      <artifactId>toplink-essentials</artifactId>
      <version>2.1-36</version>

      whatever I tried with

      @Id
      @GeneratedValue(strategy = GenerationType.

      I cannot insert any data

      with GenerationType.AUTO a sequence table is created but an exception is thrown when toplink tries to update this table

      any other type did not throw an exception and em.persist just runs without any error and no heck ! data inserted..

      count and find query runs fine , result 0..

      Comment


      • #4
        my cfg

        <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean"
        p:dataSource-ref="pooled.datasource">
        <property name="jpaVendorAdapter">

        <bean
        class="org.springframework.orm.jpa.vendor.TopLinkJ paVendorAdapter"
        p:database="${jpa.database}" p:showSql="${jpa.showSql}" p:databasePlatform="${jpa.databasePlatform}" p:generateDdl="${jpa.generateDdl}">
        </bean>

        </property>
        <property name="loadTimeWeaver">
        <bean class="org.springframework.instrument.classloading .InstrumentationLoadTimeWeaver" />
        </property>
        </bean>

        <bean id="transactionManager"
        class="org.springframework.orm.jpa.JpaTransactionM anager"
        p:entityManagerFactory-ref="entityManagerFactory" />

        <context:annotation-config />

        <tx:annotation-driven />

        props :

        jpa.showSql=true
        jpa.generateDdl=true
        jpa.databasePlatform=oracle.toplink.essentials.pla tform.database.MySQL4Platform
        jpa.database=MYSQL

        persistence.xml :

        <persistence-unit name="meat" transaction-type="RESOURCE_LOCAL">
        <provider>oracle.toplink.essentials.PersistencePro vider</provider>

        </persistence-unit>

        orm.xml :

        <persistence-unit-metadata>
        <persistence-unit-defaults>
        <access>PROPERTY</access>
        </persistence-unit-defaults>
        </persistence-unit-metadata>

        <package>wims.tijd.domain</package>

        Comment

        Working...
        X