File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes composite key by @IdClass Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "composite key by @IdClass" Watch "composite key by @IdClass" New topic
Author

composite key by @IdClass

zb cong
Ranch Hand

Joined: Jan 14, 2002
Posts: 416
hello, discuss the style of composite key by @IdClass. take the Category as example. this class use the name and createDate as comp. key. the entity part looks like:

@Entity
@IdClass(CategoryPK.class)
public class Category {
public Category() {}
@Id
protected String name;
@Id
protected Date createDate;
public String getName(){.............}
public Date getCreateDate(){..............}
public void setName(){.............}
public void setCreateDate(){.........}
}


but somebody add the @Id on getter method like:

@Entity
@IdClass(CategoryPK.class)
public class Category {
public Category() {}

protected String name;
protected Date createDate;

@Id
public String getName(){return this.name}
@Id
public Date getCreateDate(){return this.createDate}

public void setName(){.............}
public void setCreateDate(){.........}
}


it seem like both work after trying. but i have referred to at least three books, all of them just mention the first style. one of book even emphasize we must add the @id on the properties. so i am confused what's the different between them, and why the second style is not mentioned?

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: composite key by @IdClass
 
Similar Threads
@IdClass EJB 3 in Action
Hibernate, Spring and Sybase
JPA: Map composite primary key with one field being foreign key
JPA composite keys problem
A issue in Struts1.x