These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Spring hibernate one-to-many
PostPosted: Wed Sep 17, 2008 10:36 am 
Newbie

Joined: Wed Sep 17, 2008 10:28 am
Posts: 2
Iam doing Spring hibernate application. with one-to-many mapping



Iam getting following exceptipon


Creatting BankCustomerClient Started
log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
Classpath loaded
Hibernate: select hibernate_sequence.nextval from dual
Hibernate: select hibernate_sequence.nextval from dual
java.lang.ClassCastException: com.ck.spring.Customer
at org.hibernate.type.EntityType.toLoggableString(EntityType.java:463)
at org.hibernate.pretty.Printer.toString(Printer.java:53)
at org.hibernate.pretty.Printer.toString(Printer.java:90)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:97)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1004)
at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:420)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:690)
at com.ck.spring.CustomerDAOImpl.addCustomer(CustomerDAOImpl.java:21)
at com.ck.spring.BankCustomerClient.main(BankCustomerClient.java:46)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 17, 2008 3:56 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
It looks like a log4j configuration problem.
You can go here for a detailed description on how to set a Hibernate logging configuration file.

There is also a couple of sample files.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 2:42 am 
Newbie

Joined: Wed Sep 17, 2008 10:28 am
Posts: 2
-------------------------------------------------------------------------------------
This is Customer.hbm.xml




<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class name="com.ck.spring.Customer" table="SPH_CUSTOMER"
dynamic-update="false" dynamic-insert="false" >
<id name="id"
column="CUSTOMER_ID"
type="java.lang.Long"
unsaved-value="-1" >
<generator class="native"></generator>
</id>
<set name="accounts"
inverse="true"
cascade="all-delete-orphan">
<key column="CUSTOMER_ID"/>
<one-to-many class="com.ck.spring.Account"/>
</set>
<property name="email"
type="string"
update="false"
insert="true"
column="CUSTOMER_EMAIL"
length="82"
not-null="true"
/>
<property name="userId"
type="string"
update="false"
insert="true"
column="CUSTOMER_USERID"
length="15"
not-null="true"
unique="true"
/>
<property name="password"
type="string"
update="false"
insert="true"
column="CUSTOMER_PASSWORD"
length="10"
not-null="true"
/>
<property name="firstName"
type="string"
update="false"
insert="true"
column="CUSTOMER_FIRSTNAME"
length="25"
not-null="true"
/>
<property name="lastName"
type="string"
update="false"
insert="true"
column="CUSTOMER_LASTNAME"
length="25"
not-null="true"
/>
</class>
</hibernate-mapping>

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------




This is Account.hbm.xml



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0/EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class name="com.ck.spring.Account" table="SPH_ACCOUNT" dynamic-update="false" dynamic-insert="false">
<id name="id"
column="ACCOUNT_ID"
type="java.lang.Long"
unsaved-value="-1" >
<generator class="native"></generator>
</id>
<many-to-one name="customer"
column="CUSTOMER_ID"
class="com.ck.spring.Account"
not-null="true" />
<property name="accountName"
type="string"
update="false"
insert="true"
column="ACCOUNT_NAME"
length="50"
not-null="true" />
<property name="accountType"
type="string"
update="false"
insert="true"
column="ACCOUNT_TYPE"
length="1"
not-null="true" />
<property name="createdDate"
type="date"
update="false"
insert="true"
column="CREATED_DATE"
not-null="true" />
<property name="updatedDate"
type="date"
update="true"
insert="true"
column="UPDATED_DATE"
not-null="true" />
<property name="balance"
type="double"
update="true"
insert="true"
column="ACCOUNT_BALANCE"
not-null="true" />
</class>
</hibernate-mapping>

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------


This is SpringHibEx-hibernate.xml




<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" >
<!--
- Application context definition for Express on Hibernate.
-->
<beans>
<bean id="exampleDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>

<property name="url">
<value>jdbc:oracle:thin:@172.17.3.130:1521:MIRACLE</value>
</property>

<property name="username">
<value>ultima</value>
</property>

<property name="password">
<value>ultima</value>
</property>

</bean>
<bean id="exampleHibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.query.substitutions">true 'T',false 'F'</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.c3p0.minPoolSize">5</prop>
<prop key="hibernate.c3p0.maxPoolSize">20</prop>
<prop key="hibernate.c3p0.timeout">600</prop>
<prop key="hibernate.c3p0.max_statement">50</prop>
<prop key="hibernate.c3p0.testConnectionOnCheckout">false</prop>
</props>
</property>
</bean>

<!-- Hibernate SessionFactory -->
<bean id="exampleSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref local="exampleDataSource" /></property>
<property name="hibernateProperties">
<ref bean="exampleHibernateProperties" />
</property>
<!-- Must references all OR mapping files. -->
<property name="mappingResources">
<list>
<value>com/ck/spring/Customer.hbm.xml</value>
<value>com/ck/spring/Account.hbm.xml</value>
</list>
</property>
</bean>


<!-- Pass the session factory to our UserDAO -->
<bean id="customerDAOTarget" class="com.ck.spring.CustomerDAOImpl">
<property name="sessionFactory">
<ref local="exampleSessionFactory" />
</property>
</bean>


<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="exampleSessionFactory" />
</property>
</bean>

<bean id="userDAO" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref local="transactionManager" />
</property>

<property name="target">
<ref local="customerDAOTarget" />
</property>

<property name="transactionAttributes">
<props>
<prop key="addCustomer">PROPAGATION_REQUIRED</prop>
</props>
</property>

</bean>

</beans>

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------



I have a doubt with the Tables need to create for this configurations(primary keys and foreign keys).


Can you specify the table strucure (primary keys and foreign keys)[/list][/list][/url]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.