Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Question about Entity Bean @Id

 
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.
 
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.
 
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?
 
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic