Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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
 
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!