tags:

views:

363

answers:

1

I asked this earlier and was to look at mapped by.

I have 2 tables: A s_id(key) name cli type

B sa_id(key) s_id user pwd.

So in Jpa I have:

@Entity class A...{ @OneToMany(fetch=FetchType.EAGER) @JoinTable( name="A_B", joinColumns={@JoinColumn(name="a_id", table="a",unique=false)}, inverseJoinColumns={@JoinColumn(name="b_id", table="b", unique=true)} ) Collection getB(){...} }

class b is just a basic entity class with no reference to A.

Hopefully that is clear. My question is: Do I really need a join table to do such a simple join? Can't this be done with a simple joincolumn or something?

So now if Have this, but jpa is trying to write the query with some new column that doesn't exist (s_s_id)

@Entity class A{ ... @OneToMany(fetch=FetchType.EAGER, mappedBy="s") Collection x; }

@Entity class B{ @ManyToOne A s; }

With these tables: A s_id(key) name cli type

B sa_id(key) s_id(the keys from A) user pwd.

How can I do The OneToMany and ManyToOne joins such that I don't need a new column nor a new table? Please give me an example. Is the issue the lack of a foreign key in the B table?

The errors I have: If I leave out the mapped by i get this Unknown column 't1.S_S_ID' in 'field list

If I put in the mapped by I get this Unknown column 'S_S_ID' in 'field list'

+1  A: 

I found it, I need to add the @JoinColumn and give it a name...

arinte