Announcement Announcement Module
Collapse
No announcement yet.
Java To DB doesn't work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Java To DB doesn't work

    I use Oracle Toplink (which support java2db). This works fine in one application without using Spring. When I create another app, using spring, and the same other JPA configuration, I don't get any exception when add an object to the database. However, when looking at the database, the tables are not created (also, query fails because the tables are not found).

    <property name="toplink.ddl-generation" value="drop-and-create-tables"/>

    Was in the properties in the persistent.xml file.

    Does Spring support this? If so, how? Thanks.

  • #2
    It has nothing to do with Spring it is a Toplink issue and probably something in your configuration.

    Comment


    • #3
      It's good to hear. So, what possibly could be the problem here?
      After putting @Repository, I now get the exception for it, but all it says is that the tables are not found when I add an object.

      The method I use is:

      <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
      <property name="dataSource" ref="someDataSource"/>
      <property name="persistenceXmlLocation" value="classpathersistence.xml" />
      <property name="loadTimeWeaver">
      <bean class="org.springframework.instrument.classloading .InstrumentationLoadTimeWeaver"/>
      </property>
      </bean>

      Which means the J2EE container doesn't load the JPA, but Spring will take care of it (because the location of persistence file is changed).

      I also have the following (besides the data source):

      <aop:aspectj-autoproxy/>
      <tx:annotation-driven/>
      <bean class="org.springframework.orm.jpa.support.Persist enceAnnotationBeanPostProcessor"/>
      <bean class="org.springframework.dao.annotation.Persiste nceExceptionTranslationPostProcessor"/>

      One strange note is that in J2ee app, my persistence.xml doesn't require me to specify each entity class. Here, I have to do that (if not, it won't be found).

      Comment


      • #4
        Please use [ code][/code] tags when posting code/configuration.

        Can you also post the contents of your persistence.xml?

        You might also try setting a JpaVendorAdapter explicitly...
        Last edited by Marten Deinum; Nov 15th, 2007, 04:29 PM.

        Comment


        • #5
          By adding the jpaVendorAdapter property and point it to Oracle toplink, it works.

          My persistent.xml file is:

          Code:
          <?xml version="1.0" encoding="UTF-8"?>
          <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
            <persistence-unit name="PersistentAppPU" transaction-type="JTA"   >
              <provider>oracle.toplink.essentials.PersistenceProvider</provider>
              <jta-data-source>myDataSource</jta-data-source>
              <class>asdf.asdf.asdf.SomeClass</class>
              <exclude-unlisted-classes>false</exclude-unlisted-classes>
              <properties>
                <property name="hibernate.show_sql" value="true"/>
                <property name="toplink.ddl-generation" value="drop-and-create-tables"/>
              </properties>
            </persistence-unit>
          </persistence>
          There are possible 2 bugs in Spring here. First, it doesn't follow the settings here (that I had to explicitly set the oracle toplink). Second, I didn't have to specify the "SomeClass" before, now, I have to.

          Comment

          Working...
          X