Mapping composite/complex types (hibernate UserType alternative)

View: New views
2 Messages — Rating Filter:   Alert me  

Mapping composite/complex types (hibernate UserType alternative)

by jobr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

We are in the middle of researching a migration from hibernate to  
eclipselink.
However there is one thing I cannot find a good alternative for :  
hibernate UserTypes, these can be used to define your own db mappings  
for complex/composite types, eg a Money attribute. example code :

@Entity
public class Account {

    @Id
    private String accountId;
   ...
   @??
   private Money balance;
}


public class Money {

   private BigDecimal amount;
   private String currency;

   public Money(BigDecimal amount, String currency) {
     ...
   }

}

ACCOUNT table on database :

accountId    VARCHAR2(20)
balamount   NUMBER
balcurrency VARCHAR(3)
...

Is it possible with eclipselink to define a mapping on the balance  
attribute so that is maps the Money object on two different fields in  
the database (balamount & balcurrency) within the account table? (so  
we don't want a separate money table)
I 've read about converters but this seems to be limited to a one on  
one mapping, i.e. you can only map the 'balance' attribute in the  
account entity on one single column in the related table.
Am I correct here? is this not at all possible with Eclipselink? this  
would be a real showstopper for us.

cheers, Joost

_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: Mapping composite/complex types (hibernate UserType alternative)

by James Sutherland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

In JPA you can use an Embedded mapping for this.

In EclipseLink you could also map this using a TransformationMapping.

See,
http://www.eclipse.org/eclipselink/api/1.1.2/org/eclipse/persistence/annotations/Transformation.html

jobr wrote:
Hi,

We are in the middle of researching a migration from hibernate to  
eclipselink.
However there is one thing I cannot find a good alternative for :  
hibernate UserTypes, these can be used to define your own db mappings  
for complex/composite types, eg a Money attribute. example code :

@Entity
public class Account {

    @Id
    private String accountId;
   ...
   @??
   private Money balance;
}


public class Money {

   private BigDecimal amount;
   private String currency;

   public Money(BigDecimal amount, String currency) {
     ...
   }

}

ACCOUNT table on database :

accountId    VARCHAR2(20)
balamount   NUMBER
balcurrency VARCHAR(3)
...

Is it possible with eclipselink to define a mapping on the balance  
attribute so that is maps the Money object on two different fields in  
the database (balamount & balcurrency) within the account table? (so  
we don't want a separate money table)
I 've read about converters but this seems to be limited to a one on  
one mapping, i.e. you can only map the 'balance' attribute in the  
account entity on one single column in the related table.
Am I correct here? is this not at all possible with Eclipselink? this  
would be a real showstopper for us.

cheers, Joost