Win a copy of Spark in Action this week in the Open Source Projects 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Support for non standard class entity bean attributes in EJB3

 
Ranch Hand
Posts: 209
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Currently, we have an existing custom DB->obj persistence framework built on top of Session EJB and attributes are strictly represented as a hierarchy of custom domain classes wrapping basic types such as String, Date, TimeStamp, etc. We have not moved to entity EJB because it is too much work to make EJB 2 to support this, having to programmatically translate/wrap/box those attributes.

Can this custom mapping from table columns to custom attribute classes be easily supported in EJB3?
[ March 13, 2007: Message edited by: Chu Tan ]
 
author
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand your question properly but what you are looking for a Java object type as an attribute/field or an entity?

Yes, you could do that in EJB 3/JPA easily and that's called embedded type

@Entity
@Table(name = "CONTACT_DETAILS")
public class ContactInfo implements java.io.Serializable {

protected String userId;



@Id
@Column(name = "CONTACT_USER_ID")
public String getUserId() {
return this.userId;
}


@Embedded
public Address getAddress() {
return address;
}

..
}

Here is how you define Address

@Embeddable
public class Address implements java.io.Serializable {

protected String streetName1;

protected String streetName2;

protected String city;

protected String state;

protected String zipCode;

protected String country;

..}

Here both objects are mapped to the same table(s). We discuss this in depth in chapter 7 and 8 of EJB 3 In Action
 
Justin Chu
Ranch Hand
Posts: 209
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meant something like



For example, PhoneDomain essentially is just a String. When instantiating or setting the value of PhoneDomain, there are behavior to make sure it is 7 digits or 10 or 11 digits. The toString() method of PhoneDomain will output "X (XXX) XXX-XXXX".
[ March 13, 2007: Message edited by: Chu Tan ]
 
author
Posts: 580
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow! Very interesting question...my gut reaction is not really.

I think you'd have to define all of the custom classes as embedded objects that are mapped to database tables. Take a look at the @Embeddable annotation for JPA. You can have complex unique identifiers for an entity too, which appears to be what is going on for you!

In any case, interesting architecture!
[ March 14, 2007: Message edited by: Reza Rahman ]
 
Debu Panda
author
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can easily use the getter method on the entity to return the formatted value? Why do you want to create a new type?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic