persistence@glassfish.java.net

Re: foreign key reference with toplink

From: Benjamin Graf <Benjamin.Graf_at_gmx.net>
Date: Wed, 5 Apr 2006 15:51:34 +0200 (MEST)

Hi Tom,

I think both are necessary. I'm trying to create a relationship with two
entities and I thought that toplink will "translate" it to foreign key
reference as mentioned in the spec.

Code example:

@Entity
@NamedNativeQuery(name="activeBO", query="select * from boentity where
status=0", resultClass=BoEntity.class)
public class BoEntity implements java.io.Serializable {
   
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
          
    @OneToMany(cascade=CascadeType.ALL, mappedBy="bo")
    private Collection<HistoryLogEntity> history;
    ...
}

@Entity
public class HistoryLogEntity implements java.io.Serializable {
   
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="HistoryLogID")
    private Long id;
   
    @ManyToOne(cascade=CascadeType.ALL)
    private BoEntity bo;
    ...
}

Tom Ware wrote:
> Hi Benjamin,
>
> It is not clear to me which of the following you are attempting.
>
> 1. To create a OneToMany (and its corresponding ManyToOne) relationship
between two entities.
> 2. To automatically create tables from entities and have the database
foreign key constraint automatically generated.
>
> Please provide a little more detail about what you are trying to do and
the code that you are using to set up your ManyToOne.
>
> -Tom
>
> Benjamin Graf wrote:
>
>> Hi,
>>
>> does anybody know how to create a foreign key reference with toplink? I
>> tried several times with @OneToMany(mappedBy...) @ManyToOne, but I didn't
>> succeed in creating a reference in the database table. Is that a
limitation
>> of toplink because there are no further information in the
>> ejb3.0-persisitence-spec pdf-file.
>>
>> Regards, Benjamin
>>
>>
>


-- 
E-Mails und Internet immer und überall!
1&1 PocketWeb, perfekt mit GMX: http://www.gmx.net/de/go/pocketweb