• Post Reply Bookmark Topic Watch Topic
  • New Topic

Dozer copy value from one object to another  RSS feed

 
Vani Kumar
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Dozer BeanMapper to copy an object to another object based on field names. I have 4 classes, two as java classes (User, PhoneNumber) and the other as jpa entities (User, PhoneNumber)
I have to copy the User to jpa User entity object.

Java classes:

Class User{
int userid;
List<PhoneNumber> phoneNumbers;
}

Class PhoneNumber{
int userid;
String phoneNumber
}
JPA Entities:

@Entity
Class User{
int userid;
List<PhoneNumber> phoneNumbers;
}

@Entity
Class PhoneNumber{
int userid;
String phoneNumber
}

I have a mapping in dozerBeanMapping file as below

<mapping map-id="user">
<class-a>User</class-a>
<class-b>User</class-b>
<field>
<a>userid</a>
<b>userid</b>
</field>
<field>
<a>phoneNumbers</a>
<b is-accessible="true">phoneNumbers</b>
</field>
</mapping>

<mapping map-id="phoneNumbers">
<class-a>PhoneNumber</class-a>
<class-b>PhoneNumber</class-b>
<field>
<a>userid</a>
<b>userid</b>
</field>
<field>
<a>phoneNumber</a>
<b>phoneNumber</b>
</field>
</mapping>

For the PhoneNumber object, i won't be getting userid, how can i copy the userid from the map-id "user" to map-id "phoneNumbers"
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vani Kumar wrote:For the PhoneNumber object, i won't be getting userid, how can i copy the userid from the map-id "user" to map-id "phoneNumbers"

First: I know nothing about "Dozer" or bean mapping, but it seems to me that, since PhoneNumber contains a userid, it's essential. You can't just say "sorry, I won't be getting one".

Second: Java classes know nothing about "ids", unless this "Dozer" middleware has some sort of "glue" that can fit them together.
I would expect a Java PhoneNumber class to look like:But I could be totally out to lunch on this.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!