This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about Entity Bean @Id

 
Giovanni Zarc
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I create a entity bean, without write @Id?
If its not, how Can I do it? some advice?

I had a table without pk, only a fk.
 
adil qureshi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Giovanni Ascarza wrote:Can I create a entity bean, without write @Id?
If its not, how Can I do it? some advice?

I had a table without pk, only a fk.


I tried it but it doesn't worked ,its mandatory ,I suggest you use a sequence number as an id.
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need to have a primary key constraint to mark a field as @Id, it just has to be unique for your application.
If the foreign key is unique, then you can use it as the @Id.
If you truly have nothing that is unique and can't add a generated Id, then you could mark all fields as @Id.
This will work for reading, but you will not be able to update (you can delete and insert though).

http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#No_Primary_Key
 
Giovanni Zarc
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But what happends if for example I have a Table Person and Address, whose relation only is OneToMany with Address, and Address doesn't have @Id only fields and a FK referenced to Person.
In TAddress, FK is
@ManyToOne
@JoinColumns({
@JoinColumn(name = "....", referencedColumnName = "...."),
@JoinColumn(name = "....", referencedColumnName = "....")
})
private TabPersona tabPersona;

In TPerson only have:

@OneToMany(mappedBy = "tabPersona")
private Collection<Address> detAddress()

I have tested with you advice, but this case of entities doesn't find...
Some helps?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic