Using JPA and Hibernate
I have an entity class
@Entity
@Table(name = "ROLES")
public class Role implements Serializable
{
@Column
private List<String> tubes;
// another fields .setters, getters
}
Every String in List tubes – is one row from another table (TUBES).
Table ROLES has an OneToMany relationship with TUBES.
A can make another Entity Tubes and map table TUBES on Entity Tubes. But how I can make this without another entity?
Edit:
I made
@ElementCollection
@CollectionTable(name = "TUBES", joinColumns = @JoinColumn(name = "role_id"))
@Column(name = "tube")
private ArrayList<String> tubes;
Deploy on JBoss. And in runtime I get SQLGrammarException
Query created by JPA is:
/* SELECT r FROM Role r WHERE r.name = ? */ select role0_.AA_ID as AA1_0_, role0_.ROLNAME as ROLNAME0_, role0_.role as PID4_0_ from PIDDB_PID_ROLE role0_ where role0_.ROLNAME=?
17:17:14,661 ERROR [JDBCExceptionReporter] ORA-00904: "ROLE0_"."tube": invalid identifier
You can use
@ElementCollectionmapping I think this is what are you looking for.Update: