Wrong One-To-Many Mapping

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

Wrong One-To-Many Mapping

by PLC_David :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I tested the jpa with the eclipseLink provider.
But I have many problems with the annotations.

My DTOs:

@Entity
@Table(name=PLC.BOOKS)
public BookDTO {

int id;
...
@OneToMany
List<ChapterDTO> chapterList;
}

@Entity
@Table(name=PLC.CHAPTERS)
ChapterDTO {
int id;
@Embedded
AutorDTO autor;
...
}

@Embeddable
AutorDTO {

String ...
...
}


I have a one-to-many relationship. There is a column BOOK_ID in the table CHAPTERS which realize this relationship.

But JPA generates the wrong select. It takes a column which not exists.
select ..... from ... where t0.id = .. and t1.id = t0.chapterList_ID

Can anybody tell me what I need at this relationship?

Re: Wrong One-To-Many Mapping

by cowwoc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


The Javadoc for OneToMany might help you: http://java.sun.com/javaee/5/docs/api/javax/persistence/OneToMany.html

You probably want to specify @JoinColumn(name="BOOK_ID")

Gili

PLC_David wrote:
Hi,

I tested the jpa with the eclipseLink provider.
But I have many problems with the annotations.

My DTOs:

@Entity
@Table(name=PLC.BOOKS)
public BookDTO {

int id;
...
@OneToMany
List<ChapterDTO> chapterList;
}

@Entity
@Table(name=PLC.CHAPTERS)
ChapterDTO {
int id;
@Embedded
AutorDTO autor;
...
}

@Embeddable
AutorDTO {

String ...
...
}


I have a one-to-many relationship. There is a column BOOK_ID in the table CHAPTERS which realize this relationship.

But JPA generates the wrong select. It takes a column which not exists.
select ..... from ... where t0.id = .. and t1.id = t0.chapterList_ID

Can anybody tell me what I need at this relationship?

Re: Wrong One-To-Many Mapping

by zebhed :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


cowwoc wrote:
The Javadoc for OneToMany might help you: http://java.sun.com/javaee/5/docs/api/javax/persistence/OneToMany.html

You probably want to specify @JoinColumn(name="BOOK_ID")

Gili
if the relationship is unidirectional (1 ---> N) you have to specifiy a join table. (JPA 1.0)

Re: Wrong One-To-Many Mapping

by PLC_David :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


zebhed wrote:
if the relationship is unidirectional (1 ---> N) you have to specifiy a join table. (JPA 1.0)

@OneToMany
@JoinTable(name="CHAPTERS", joinColumns=@JoinColumn(name="BOOK_ID",referencedColumnName="BOOK_ID"))


JPA doesn't generate the right select. Which properties are missing ?

David

Re: Wrong One-To-Many Mapping

by zebhed :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

an example:

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "lkp_books_chapters", joinColumns = {@JoinColumn(name = "_book_id", updatable = false)}, inverseJoinColumns = {@JoinColumn(name = "_chapter_id", updatable = false)})
private List<Chapter> chapters;

you should buy a book about EJB (JPA).


PLC_David wrote:
@OneToMany
@JoinTable(name="CHAPTERS", joinColumns=@JoinColumn(name="BOOK_ID",referencedColumnName="BOOK_ID"))


JPA doesn't generate the right select. Which properties are missing ?

David

Re: Wrong One-To-Many Mapping

by PLC_David :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


zebhed wrote:
an example:

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "lkp_books_chapters", joinColumns = {@JoinColumn(name = "_book_id", updatable = false)}, inverseJoinColumns = {@JoinColumn(name = "_chapter_id", updatable = false)})
private List<Chapter> chapters;

you should buy a book about EJB (JPA).
Thank you very much, I test multiple persistence framework. I don't have enough money to buy a book for each framework.

greetz David