Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » eclipselink + JPA + Postgresql - is possible embedded ?(is posible use embedded and @AttributeOverrides with postgresql)
eclipselink + JPA + Postgresql - is possible embedded ? [message #659747] Tue, 15 March 2011 13:21 Go to next message
Adam  is currently offline Adam
Messages: 6
Registered: March 2011
Junior Member
Hello everyone,

I'm begginer in Java and also in JPA.. Unfortunately i have to work with postgresql + JPA + eclipselink, because is my school project. Database is final and i can't do any changes even if i wanted to. In structure of DB is this.
--
-- Name: address; Type: TYPE; Schema: artio; Owner: facman
--

  
CREATE TYPE address AS (
street character varying,
city character varying,
state character varying,
country character varying,
zip character varying,
note character varying
);
ALTER TYPE artio.address OWNER TO facman;


here is screenshot of this custom type in my table http://img822.imageshack.us/i/18591958.png

1. is even possible to use @embedded and @AttributeOverrides for postgresql ?

I was trying by myself some code : but no success. Because if i want select directly street, i must use in sql something like this:
(address)."street" ... but if i want to save something it must be address."street" without "( )" and this is the issue.
@Entity
@Table(name = "\"Property\"", catalog = "", schema = "public", uniqueConstraints = {@UniqueConstraint(columnNames = {"code"})})
public class Property implements Serializable {  
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false) 
    @Column(name = "\"propertyID\"", nullable = false)
    private Long propertyID;
    @Column(name = "code", length = 20)
    private String code;
    @Basic(optional = false)
    @Column(name = "\"name\"", nullable = false, length = 200)
    private String name;    
    @Embedded
    @AttributeOverrides({
        @AttributeOverride(name = "street", column =
        @Column(name = "********"))
    })
private Address address;


I don't know what i should put instead ********* because if i put there "address" then i get object: Address.getStreet() but in this object is all address means (Street,city,state,zip...)
if i put street instead of ******* than i have sql error that column street does not exist, which is right. It doesn't . Only way i can get it is (address).street but if i put this instead of ****** than i get the same error as previous. System somehow change (address).street only into street. I need help how deal with it. I need to be able to selected/insert/update separate part of address as street,city,etc.

public class Address implements Serializable {
    protected String street;

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }
}

I spend 14 hours to find out and im exhausted.
PLEASE HELP ME Sad
Best Regards Adam
Re: eclipselink + JPA + Postgresql - is possible embedded ? [message #659777 is a reply to message #659747] Tue, 15 March 2011 15:07 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1035
Registered: July 2009
Senior Member
Hello,

Embeddable is used for objects that exist using the same database row as the parent object. The embeddable itself doesn't have its own table. What you are looking for is nested table support, which doesn't exist in JPA.

EclipseLink has support for object-relational data types described here:
http://wiki.eclipse.org/Introduction_to_Object-Relational_Da ta_Type_Mappings_(ELUG)
This will require a customizer to implement the mappings, so you will need to mark the address attribute as @Transient so it doesn't get default mappings for it, and then add a StructMapping to the Property Descriptor and ObjectRelationalDataTypeDescriptor for Address in the customizer. An example is the PolicyHolder->Address relationship found here:
http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/tr unk/foundation/eclipselink.core.test/src/org/eclipse/persist ence/testing/models/insurance/objectrelational/

You can also use a @StructConverter annotation:
http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#How_to_Use_the_.40StructConverter_Annotation
This allows you to set up your own StructConverter for your platform to convert to/from the java object, but you will have to write the implementing class yourself.

Best Regards,
Chris
Re: eclipselink + JPA + Postgresql - is possible embedded ? [message #659781 is a reply to message #659777] Tue, 15 March 2011 15:26 Go to previous messageGo to next message
Adam  is currently offline Adam
Messages: 6
Registered: March 2011
Junior Member
Thank you for your reply. Now, let me say WOW .. this looks realy difficult for me... but i suggest there is no easier way is it ?
Re: eclipselink + JPA + Postgresql - is possible embedded ? [message #659782 is a reply to message #659781] Tue, 15 March 2011 15:31 Go to previous message
Adam  is currently offline Adam
Messages: 6
Registered: March 2011
Junior Member
BTW in this page http://wiki.eclipse.org/Introduction_to_Object-Relational_Da ta_Type_Mappings i see only this message:There is currently no text in this page, you can search for this page title in other pages or edit this page.
Previous Topic:problem with dynamic weaving and class hierarchy
Next Topic:Isolated Client Session per Request
Goto Forum:
  


Current Time: Thu Oct 30 19:04:43 GMT 2014

Powered by FUDForum. Page generated in 0.02812 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software