Attached is the javabean code and the generated schema. Please look at how in the generated schema, the primary key is the combination of just the BAR_ID and BAR_IDX.
How do I get the primary key to be FOO_ID, BAR_ID and BAR_IDX?
I may be totally off track here in defining the relationships. Please let me know if there is a better way of modelling the two entities?
Thanks a lot,
Irfan
Foo2:
----------------------------------------------------------------------------
package com.samples.foobar;
import com.samples.core.impl.AbstractCoreObject;
import java.util.ArrayList;
import java.util.List;
/**
* Foo2.
*
* @hibernate.class table="FOO2" dynamic_update="true"
*/
public class Foo2 extends AbstractCoreObject {
/** name */
private String name_;
/** Id */
private String id_;
/** uri */
private String uri_;
/** list of bars */
private List barList_ = new ArrayList(10);
/**
* {@inheritDoc}
*/
public boolean equals(Object obj) {
boolean isEqual = (this == obj);
if (!isEqual && (obj instanceof Foo2)) {
Foo2 that = (Foo2) obj;
isEqual = this.uri_.equals(that.uri_);
}
return isEqual;
}
/**
* {@inheritDoc}
*/
public int hashCode() {
return this.uri_.hashCode();
}
/**
* returns the list of bars.
*
* @return the list of bars.
*
* @hibernate.list table="FOO_BAR2" lazy="true" cascade="all"
* @hibernate.collection-key column="FOO_ID"
* @hibernate.collection-index column="BAR_IDX"
* @hibernate.collection-many-to-many column="BAR_ID" class="com.samples.foobar.Bar2"
*/
public List getBarList() {
return this.barList_;
}
/**
* returns the id.
*
* @return the id.
*
* @hibernate.id column="ID" not-null="true" unsaved-value="null" type="string" length="32" generator-class="uuid.hex"
*/
public String getId() {
return this.id_;
}
/**
* returns the name.
*
* @return the name.
*
* @hibernate.property column="NAME" not-null="true" unsaved-value="null" type="string" length="255"
*/
public String getName() {
return this.name_;
}
/**
* sets the list of bars.
*
* @param barList The bar List to set.
*/
public void setBarList(List barList) {
this.barList_ = barList;
}
/**
* sets the id.
*
* @param id The id to set.
*/
public void setId(String id) {
this.id_ = id;
}
/**
* sets the name.
*
* @param name The name to set.
*/
public void setName(String name) {
this.name_ = name;
}
/**
* adds the bar.
*
* @param bar bar
*/
public void addBar(Bar2 bar) {
this.barList_.add(bar);
}
/**
* removes the bar.
*
* @param bar bar
*/
public void removeBar(Bar2 bar) {
this.barList_.remove(bar);
}
/**
* returns the uri.
*
* @return the uri.
*
* @hibernate.property column="URI" not-null="true" unsaved-value="null" type="string" length="255"
*/
public String getUri() {
return this.uri_;
}
/**
* sets the uri.
*
* @param uri The uri to set.
*/
public void setUri(String uri) {
this.uri_ = uri;
}
}
Bar2:
----------------------------------------------------------------------------
package com.samples.foobar;
import com.samples.core.impl.AbstractCoreObject;
import java.util.ArrayList;
import java.util.List;
/**
* Bar2.
*
* @hibernate.class table="BAR2" dynamic_update="true"
*/
public class Bar2 extends AbstractCoreObject {
/** name */
private String name_;
/** Id */
private String id_;
/** uri */
private String uri_;
/** list of foos */
private List fooList_ = new ArrayList(10);
/**
* {@inheritDoc}
*/
public boolean equals(Object obj) {
boolean isEqual = (this == obj);
if (!isEqual && (obj instanceof Bar2)) {
Bar2 that = (Bar2) obj;
isEqual = this.uri_.equals(that.uri_);
}
return isEqual;
}
/**
* {@inheritDoc}
*/
public int hashCode() {
return this.uri_.hashCode();
}
/**
* returns the list of foos.
*
* @return the list of foos.
*
* @hibernate.list table="FOO_BAR2" lazy="true" cascade="all" inverse="true"
* @hibernate.collection-key column="BAR_ID"
* @hibernate.collection-index column="BAR_IDX"
* @hibernate.collection-many-to-many column="FOO_ID" class="com.samples.foobar.Foo2"
*/
public List getFooList() {
return this.fooList_;
}
/**
* returns the id.
*
* @return the id.
*
* @hibernate.id column="ID" not-null="true" unsaved-value="null" type="string" length="32" generator-class="uuid.hex"
*/
public String getId() {
return this.id_;
}
/**
* returns the name.
*
* @return the name.
*
* @hibernate.property column="NAME" not-null="true" unsaved-value="null" type="string" length="255"
*/
public String getName() {
return this.name_;
}
/**
* sets the list of foos.
*
* @param fooList The foo List to set.
*/
public void setFooList(List fooList) {
this.fooList_ = fooList;
}
/**
* sets the id.
*
* @param id The id to set.
*/
public void setId(String id) {
this.id_ = id;
}
/**
* sets the name.
*
* @param name The name to set.
*/
public void setName(String name) {
this.name_ = name;
}
/**
* adds the foo.
*
* @param foo foo
*/
public void addFoo(Bar2 foo) {
this.fooList_.add(foo);
}
/**
* removes the foo.
*
* @param foo foo
*/
public void removeFoo(Bar2 foo) {
this.fooList_.remove(foo);
}
/**
* returns the uri.
*
* @return the uri.
*
* @hibernate.property column="URI" not-null="true" unsaved-value="null" type="string" length="255"
*/
public String getUri() {
return this.uri_;
}
/**
* sets the uri.
*
* @param uri The uri to set.
*/
public void setUri(String uri) {
this.uri_ = uri;
}
}
Generated Schema:
----------------------------------------------------------------------------
alter table FOO_BAR2 drop constraint FK46C71E987BF1D354;
alter table FOO_BAR2 drop constraint FK46C71E98745A84E7;
drop table FOO2 cascade constraints;
drop table BAR2 cascade constraints;
drop table FOO_BAR2 cascade constraints;
create table FOO2 (
ID VARCHAR2(32) not null,
NAME VARCHAR2(255) not null,
URI VARCHAR2(255) not null,
primary key (ID)
);
create table BAR2 (
ID VARCHAR2(32) not null,
NAME VARCHAR2(255) not null,
URI VARCHAR2(255) not null,
primary key (ID)
);
create table FOO_BAR2 (
FOO_ID VARCHAR2(32) not null,
BAR_ID VARCHAR2(32) not null,
BAR_IDX NUMBER(10,0) not null,
primary key (BAR_ID, BAR_IDX)
);
alter table FOO_BAR2 add constraint FK46C71E987BF1D354 foreign key (FOO_ID) references FOO2;
alter table FOO_BAR2 add constraint FK46C71E98745A84E7 foreign key (BAR_ID) references BAR2;
|