Help coderanch get a
new server
by contributing to the fundraiser
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dozer copy value from one object to another

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
What a stench! Central nervous system shutting down. Save yourself tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic