Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

.MappingException

 
camelia codarcea
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good evening

I have a problem and I try for some houres to find the error, but I can't:

I have two tables: User and Profiles, and they should be in a one-to-many relation: a user can have more profiles.

The error I get is: " org.hibernate.MappingException: Association references unmapped class: ProfileDAO "

here are posted the UserDAO.java and the UserDAO.hbm.xml and ProfileDAO.java and ProfileDAO.hbm.java

Please, help me !!!

UserDAO:
public class UserDAO implements Serializable{

private String telNumber; //primary key
private String sipID; //unique
private String ruleBookName; //unique

private Set profiles = new HashSet();

public void setTelNumber(String telNumber){
this.telNumber = telNumber;
}

public String getTelNumber(){
return this.telNumber;
}


public void setSipID(String sipID){
this.sipID = sipID;
}

public String getSipID(){
return this.sipID;
}


public void setRuleBookName(String ruleBookName){
this.ruleBookName = ruleBookName;
}

public String getRuleBookName(){
return this.ruleBookName;
}


public boolean equals(Object object) {
if (!(object instanceof UserDAO)) {
return false;
}

UserDAO rhs = (UserDAO) object;

return (this.telNumber).equals(rhs.telNumber);
}


public int hashCode() {
return this.telNumber.hashCode();
}
}



ProfileDAO:
public class ProfileDAO implements Serializable{

private int profileId; //key

private String profileName;
private String telNumber; //foreign key
private boolean voiceMailFlag;
private boolean serialRingingFlag;
private boolean emailFlag;
private boolean forwardToNumberFlag;



private void setProfileId(int profileId){
this.profileId = profileId;
}

public int getProfileId(){
return this.profileId;
}


private void setProfileName(String profileName){
this.profileName = profileName;
}

public String getProfileName(){
return this.profileName;
}


private void setTelNumber(String telNumber){
this.telNumber = telNumber;
}

public String getTelNumber(){
return this.telNumber;
}


public void setVoiceMailFlag(boolean voiceMailFlag){
this.voiceMailFlag = voiceMailFlag;
}

public boolean getVoiceMailFlag(){
return this.voiceMailFlag;
}


public void setSerialRingingFlag(boolean serialRingingFlag){
this.serialRingingFlag = serialRingingFlag;
}

public boolean getSerialRingingFlag(){
return this.serialRingingFlag;
}


public void setEmailFlag(boolean emailFlag){
this.emailFlag = emailFlag;
}

public boolean getEmailFlag(){
return this.emailFlag;
}


public void setForwardToNumberFlag(boolean forwardToNumberFlag){
this.forwardToNumberFlag = forwardToNumberFlag;
}

public boolean getForwardToNumberFlag(){
return this.forwardToNumberFlag;
}


public boolean equals(Object object) {
if (!(object instanceof ProfileDAO)) {
return false;
}

ProfileDAO rhs = (ProfileDAO) object;

return (this.profileName).equals(rhs.profileName);
}


public int hashCode() {
return this.profileName.hashCode();
}
}


UserDAO.hbm.xml
<hibernate-mapping>
<class name="user.UserDAO" table="User">

<id name="telNumber" type="string" column="TelNumber">
</id>

<property name="sipID" type="string" column="SipID" unique="true"/>

<property name="ruleBookName" type="string" column="RuleBookName" unique="true"/>

<set name="profiles" inverse="true">
<key column="TelNumber"/>
<one-to-many class="ProfileDAO"/>
</set>

</class>
</hibernate-mapping>


ProfileDAO.hbm.xml
<hibernate-mapping>
<class name="user.ProfileDAO" table="Profile">

<id name="profileId" column="ProfileId">
<generator class="native"/>
</id>

<property name="profileName" type="string" column="ProfileName"/>

<many-to-one name="telNumber" column="TelNumber" not-null="true"/>

<property name="voiceMailFlag" type="boolean" column="VoiceMailFlag" not-null="true"/>

<property name="serialRingingFlag" type="boolean" column="SerialRingingFlag" not-null="true"/>

<property name="emailFlag" type="boolean" column="EmailFlag" not-null="true"/>

<property name="forwardToNumberFlag" type="boolean" column="ForwardToNumberFlag" not-null="true"/>

</class>
</hibernate-mapping>

Thank you
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<one-to-many class="ProfileDAO"/>


Should be

 
camelia codarcea
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh... I missed that :roll: ; Thank you very much

But now I get another error, and I don't know what the problem is:
" Initial SessionFactory creation failed.org.hibernate.MappingException: An association from the table Profile refers to an unmapped class: java.lang.String "

I don't understand: doesn't hibernate know how to map the String class into string type ? I am really in the fog here.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<many-to-one name="telNumber" column="TelNumber" not-null="true"/>


This association mapping looks to be the problem. Change it to:



And you should correspondingly have the getter/setter for the "user" in the ProfileDAO class:

 
camelia codarcea
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, am have made the change, and it works fain now.

Thank you very much
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic