-
Jun 27th, 2007, 06:24 AM
#1
Where to put the "hibernate.hbm2ddl.auto" property
Hi. I am using Spring with Hibernate 3.3.0 and Derby DB. All is well for reading the database but when I am trying to "persist" I get this error:
SEVERE: Table/View 'HIBERNATE_UNIQUE_KEY' does not exist.
I understood that, to prevent this error from happening I have to set the property hibernate.hbmddl.auto to "update". How can I do that ?
Thank you.
Here is the applicationContext.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schem...ing-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean
class="org.springframework.orm.jpa.support.Persist enceAnnotationBeanPostProcessor" />
<bean id="personService" class="quickstart.service.PersonServiceImpl" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.Hibernat eJpaVendorAdapter">
<property name="databasePlatform" value="org.hibernate.dialect.DerbyDialect" />
<property name="showSql" value="true" />
</bean>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
<property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver" />
<property name="url" value="jdbc:derby://localhost:1527/db" />
<property name="username" value="user" />
<property name="password" value="password" />
</bean>
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionM anager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="personAction" scope="prototype"
class="quickstart.action.PersonAction">
<constructor-arg ref="personService" />
</bean>
</beans>
-
Jun 27th, 2007, 07:08 AM
#2
I see you use JPA, you could put it into your persistence.xml file, like in this example :
http://tudu.svn.sourceforge.net/view...95&view=markup
It's an Hibernate property like the "hibernate.cache.provider_class" that is configured in this example, just configure it the same way.
-
Jun 27th, 2007, 07:21 AM
#3
I resolved the issue by putting the property:
<property name="generateDdl" value="true" />
in the JpaVendorAdapter bean.
Now I have another problem. I am using an identity ID for my table (Derby DB) and when I try to perisist I get this error:
Caused by: org.apache.derby.client.am.SqlException: Attempt to modify an identity column 'ID'.
at org.apache.derby.client.am.Statement.completeSqlca (Unknown Source)
at org.apache.derby.client.net.NetStatementReply.pars ePrepareError(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.pars ePRPSQLSTTreply(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.read PrepareDescribeOutput(Unknown Source)
at org.apache.derby.client.net.StatementReply.readPre pareDescribeOutput(Unknown Source)
at org.apache.derby.client.net.NetStatement.readPrepa reDescribeOutput_(Unknown Source)
at org.apache.derby.client.am.Statement.readPrepareDe scribeOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.readP repareDescribeInputOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.flowP repareDescribeInputOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.prepa re(Unknown Source)
at org.apache.derby.client.am.Connection.prepareState mentX(Unknown Source)
Any idea ?
-
Jun 11th, 2008, 03:41 AM
#4
hi
i think u are trying to do manual insert like inserting sample data! For this u need to update the creation script in Derby like below:
CREATE TABLE ABC(column1 INT GENERATED BY DEFAULT AS IDENTITY, column2 INT)
then insertion script into table .......
and again issue an ALTER TABLE statement for the identity column
like
ALTER TABLE ABC ALTER COLUMN column1 RESTART WITH <latest_count>
hope this might be helpful
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules