Click here to Skip to main content
15,918,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello , I have a problem which i cant solve.I searched all around google and found nothing good here...
Im trying to make relation beetwen two classes : Client(one-to-many) - Account(many-to-one)but i get an exception :
org.hibernate.MappingException: Association references unmapped class: Account


but the xml seems ok for me.Anyone can tell me whats wrong?>



Client xml:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                                   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated May 27, 2015 12:21:43 AM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
	<class name="Client" table="CLIENT">
		<id name="id" type="int">
			<column name="ID" />
			<generator class="identity" />
		</id>
		<property generated="never" lazy="false" name="firstName"
			type="java.lang.String">
			<column name="FIRSTNAME" />
		</property>
		<property generated="never" lazy="false" name="lastName"
			type="java.lang.String">
			<column name="LASTNAME" />
		</property>
		<property generated="never" lazy="false" name="age" type="int">
			<column name="AGE" />
		</property>
		<property generated="never" lazy="false" name="mail"
			type="java.lang.String">
			<column name="eMAIL" />
		</property>
		<property generated="never" lazy="false" name="phone" type="int">
			<column name="PHONE" />
		</property>
		<set inverse="true" lazy="true" name="account" sort="unsorted">
			<key column="id" />
			<one-to-many class="Account" />
		</set>
	</class>
</hibernate-mapping>


Account xml:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated May 27, 2015 1:15:20 AM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
	<class name="com.bank.bank.pojo.Account" table="ACCOUNT">
		<id name="id" type="int">
			<column name="ID" />
			<generator class="assigned" />
		</id>
		<property name="name" type="java.lang.String">
			<column name="NAME" />
		</property>
		<property name="clientId" type="int">
			<column name="CLIENTID" />
		</property>
		<property name="bankId" type="int">
			<column name="BANKID" />
		</property>
		<property name="balance" type="double">
			<column name="BALANCE" />
		</property>
		<property name="currency" type="java.lang.String">
			<column name="CURRENCY" />
		</property>
		<property name="iBan" type="java.lang.String" access="field">
			<column name="IBAN" />
		</property>

		<many-to-one name="client" class="Client" column="id" />
	</class>
</hibernate-mapping>


cfg xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                         "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
	<session-factory>
		<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
		<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/bank_db</property>
		<property name="hibernate.connection.username">root</property>
		<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
		<mapping resource="com/bank/bank/pojo/Account.hbm.xml" />
		<mapping resource="com/bank/bank/pojo/Bank.hbm.xml" />
		<mapping resource="com/bank/bank/pojo/Client.hbm.xml" />
	</session-factory>
</hibernate-configuration>
Posted
Updated 27-May-15 9:37am
v2
Comments
Shubhashish_Mandal 27-May-15 8:01am    
Instead of providing the link , copy & paste the xml here. Sometime firewall block external xml to view. I guess you refering Account bean but somehow it does not visible to the container.May be you forget to define that bean.

1 solution

For "class" attribute use full class name along with package name instead of the class name. i.e
HTML
use this 
<one-to-many class="com.bank.bank.pojo.Account" />
instead of
<one-to-many class="Account" />
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900