-->
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.  [ 6 posts ] 
Author Message
 Post subject: org.hibernate.MappingException: Unknown entity
PostPosted: Fri Jan 06, 2006 5:52 am 
Newbie

Joined: Fri Jan 06, 2006 5:21 am
Posts: 2
Location: Mumbai
Hi
Need help on hibernate.
I am getting the following error. "org.hibernate.MappingException: Unknown entity"
I am creating new transaction objects for telephone and address objects and then calling commit.

The log is as follows

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Hibernate: select hibernate_sequence.nextval from dual
Hibernate: select hibernate_sequence.nextval from dual
Hibernate: select hibernate_sequence.nextval from dual
Hibernate: select hibernate_sequence.nextval from dual
org.hibernate.MappingException: Unknown entity: com.proj.common.entities.dvos.Telephone
org.hibernate.MappingException: Unknown entity: com.proj.common.entities.dvos.Telephone
org.hibernate.MappingException: Unknown entity: com.proj.common.entities.dvos.Telephone
org.proj.MappingException: Unknown entity: com.proj.common.entities.dvos.Address
java.lang.NullPointerException
Hibernate: select hibernate_sequence.nextval from dual
java.lang.NullPointerException

Thanks
Vipin


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 06, 2006 6:25 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
You did not supply much details about your code.

A reason could be that you did not include your mapping file in your hibernate.cfg.xml

e.g.
<mapping resource="de/laliluna/example2/Address.hbm.xml" />

Regards
Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 06, 2006 7:11 am 
Newbie

Joined: Fri Jan 06, 2006 5:21 am
Posts: 2
Location: Mumbai
Thanks Sebastian
I have included all the mapping files associated in the hibernate config.
But its giving error only for the telephone and address tables.
Before this user table is dependent on company table which in turn uses telephone and address.

I think its difficult to explain the full code structure here.

But telephone and address class has just getters and setters.

The company mapping file code snippet is as follows

<?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 package="com.bluecycle.profile.users.entities">
<class name="CompanyDetails" lazy="false" table="company_profiles" optimistic-lock="none">
<id name="companyProfileId" type="long" unsaved-value="null" column="company_profile_id">
<generator class="sequence"/>
</id>
<property name="companyName" type="string" column="company_name" not-null="true"/>
<property name="companyEmail" type="string" column="company_email" length="80"/>
<property name="url" type="string" column="url"/>
<component name="workPhone" update="true" insert="true" class="com.bluecycle.common.entities.dvos.Telephone">
<property name="isdn" type="string" column="work_ph_isdn" length="10" not-null="true"/>
<property name="number" type="string" column="work_ph_number" length="15" not-null="true"/>
<property name="extension" type="string" column="work_ph_ext" length="10"/>
</component>
<component name="mobileNumber" update="true" insert="true" class="com.bluecycle.common.entities.dvos.Telephone">
<property name="isdn" type="string" column="mobile_isdn" length="10" not-null="true"/>
<property name="number" type="string" column="mobile_number" length="15" not-null="true"/>
<property name="extension" type="string" column="mobile_ext" length="10"/>
</component>
<component name="fax" update="true" insert="true" class="com.bluecycle.common.entities.dvos.Telephone">
<property name="isdn" type="string" column="fax_isdn" length="10" not-null="true"/>
<property name="number" type="string" column="fax_number" length="15" not-null="true"/>
<property name="extension" type="string" column="fax_ext" length="10"/>
</component>
<component name="companyAddress" update="true" insert="true" class="com.bluecycle.common.entities.dvos.Address">
<property name="line1" type="string" column="address_line1" not-null="true" length="80"/>
<property name="line2" type="string" column="address_line2" length="80"/>
<property name="line3" type="string" column="address_line3" length="80"/>
<property name="line4" type="string" column="address_line4" length="80"/>
<property name="townOrCity" type="string" column="town_or_city" not-null="true" length="40"/>
<property name="zipOrPostcode" type="string" column="zip_or_postcode" not-null="true" length="20"/>
<property name="stateOrCounty" type="string" column="state_or_county" not-null="true" length="40"/>
<property name="countryId" type="long" column="country" not-null="true"/>
</component>
</class>
</hibernate-mapping>

Thanks
Vipin


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 06, 2006 7:59 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
I tried your code, cut away some parts and it seem to work here. Below you can find my code. I used Hibernate 3.1 with PostgreSQL 8.1
Please consider to cut away everything from your code until you come accross the issue.

Please post this here.
Sebastian

Code:
   Session session = HibernateSessionFactory.currentSession();
      Transaction tx = session.beginTransaction();
      Telephone telephone = new Telephone();
      telephone.setIsdn("123");
      telephone.setNumber("345");
      Telephone t2 = new Telephone();
      t2.setIsdn("1234");
      t2.setNumber("3434");
      Test test = new Test();
      test.setPrivatePhone(t2);
      test.setCompanyName("comp");
      test.setWorkPhone(telephone);
      session.save(test);
      tx.commit();


Code:
<?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 package="de.laliluna.component1">
  <class name="Test" lazy="false" table="test" optimistic-lock="none">
    <id name="id" type="integer" unsaved-value="null" column="id">
      <generator class="sequence">
        <param name="sequence">test_id_seq</param>
      </generator>
    </id>
    <property name="companyName" type="string" column="company_name" not-null="true" />
    <component name="workPhone" update="true" insert="true" class="de.laliluna.component1.Telephone">
      <property name="isdn" type="string" column="isdn" length="10" not-null="true" />
      <property name="number" type="string" column="number" length="15" not-null="true" />
    </component>
    <component name="privatePhone" update="true" insert="true" class="de.laliluna.component1.Telephone">
      <property name="isdn" type="string" column="isdn2" length="10" not-null="true" />
      <property name="number" type="string" column="number2" length="15" not-null="true" />
    </component>

  </class>
</hibernate-mapping>


Code:
package de.laliluna.component1;

public class Telephone {
   private String isdn;
   private String number;
   public String getIsdn() {
      return isdn;
   }
   public void setIsdn(String isdn) {
      this.isdn = isdn;
   }
   public String getNumber() {
      return number;
   }
   public void setNumber(String number) {
      this.number = number;
   }
   
}


Code:
package de.laliluna.component1;

public class Test {
   private Integer id;
   private String companyName;
   private Telephone workPhone;
   
   private Telephone privatePhone;
   
   public Telephone getPrivatePhone() {
      return privatePhone;
   }
   public void setPrivatePhone(Telephone privatePhone) {
      this.privatePhone = privatePhone;
   }
   public String getCompanyName() {
      return companyName;
   }
   public void setCompanyName(String companyName) {
      this.companyName = companyName;
   }
   public Integer getId() {
      return id;
   }
   public void setId(Integer id) {
      this.id = id;
   }
   public Telephone getWorkPhone() {
      return workPhone;
   }
   public void setWorkPhone(Telephone workPhone) {
      this.workPhone = workPhone;
   }
   
}

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 06, 2006 8:20 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Just an idea:
Do you call session.save(telephone)? This is of course false. You must call session.save(company)

Regards

Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 06, 2006 11:13 am 
Regular
Regular

Joined: Tue Jan 03, 2006 9:52 am
Posts: 52
Location: Zurich
Something is not consistent:
The error message says:
Unknown entity: com.proj.common.entities.dvos.Telephone

And your mapping document:
com.bluecycle.common.entities.dvos.Telephone

Do your add the correct hbm.xml files?

Urs


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.