• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Dozer copy value from one object to another  RSS feed

 
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"
 
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!