Hi:
I am tryingto use SchemaExport and trying to map a Hashmap. I have 2 classes : TestParent and TestChildren. TestParent contains a hashmap of children with date_id as the key(one to many mapping).
My mapping files and java classes:
public class TestParent implements Serializable {
/** identifier field */
private int parentId;
private Map children;
public TestParent() {
}
public int getParentId() {
return this.parentId;
}
public void setParentId(int parentId) {
this.parentId = parentId;
}
public Map getChildren() {
return this.children;
}
public void setChildren(Map children) {
this.children = children;
}
}
public class TestChild implements Serializable {
private int parentId;
private int childId;
private Date dateId;
public TestChild() {
}
public int getParentId() {
return this.parentId;
}
public void setParentId(int parentId) {
this.parentId = parentId;
}
public int getChildId() {
return this.childId;
}
public void setChildId(int childId) {
this.childId = childId;
}
public Date getDateId() {
return this.dateId;
}
public void setDateId(Date dateId) {
this.dateId = dateId;
}
}
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class
name="TestParent"
table="TEST_TL_PARENT"
>
<id
name="parent_id"
type="int"
column="PARENT_ID"
>
<generator class="assigned" />
</id>
<map name="Children" table="Children">
<key column="parent_id"/>
<index column="date_id" type="java.util.Date"/>
<one-to-many class="TestChild" />
</map>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class
name="TestChild"
table="TEST_TL_CHILD"
>
<id
name="childId"
type="int"
column="CHILD_ID"
>
<generator class="assigned" />
</id>
<property
name="dateID"
type="java.util.Date"
column="DATE_ID"
not-null="true"
/>
<property
name="parentID"
type="int"
column="PARENT_ID"
not-null="true"
/>
</class>
</hibernate-mapping>
I get the following error at run time :
C:\hibernate-2.1\bin>SchemaExport.bat C:\test\TestParent.hbm.xml C:\test\TestChild.hbm.xml
May 10, 2004 12:57:29 PM alter table TEST_TL_CHILD drop constraint FK39AEA9827B66B0D0
drop table TEST_TL_CHILD cascade constraints
drop table TEST_TL_PARENT cascade constraints
create table TEST_TL_CHILD (CHILD_ID NUMBER(10,0) not null, DATE_ID DATE not null, PARENT_ID NUMBER(10,0)
not null, parent_id NUMBER(10,0), date_id DATE, primary key (CHILD_ID))
May 10, 2004 12:57:31 PM net.sf.hibernate.tool.hbm2ddl.SchemaExport execute
SEVERE: Unsuccessful: create table TEST_TL_CHILD (CHILD_ID NUMBER(10,0) not null, DATE_ID DATE not null,
PARENT_ID NUMBER(10,0) not null, parent_id NUMBER(10,0), date_id DATE, primary key (CHILD_ID))
May 10, 2004 12:57:31 PM net.sf.hibernate.tool.hbm2ddl.SchemaExport execute
SEVERE: ORA-00957: duplicate column name
create table TEST_TL_PARENT (PARENT_ID NUMBER(10,0) not null, primary key (PARENT_ID))
alter table TEST_TL_CHILD add constraint FK39AEA9827B66B0D0 foreign key (parent_id) references TEST_TL_PA
RENT
May 10, 2004 12:57:32 PM net.sf.hibernate.tool.hbm2ddl.SchemaExport execute
SEVERE: Unsuccessful: alter table TEST_TL_CHILD add constraint FK39AEA9827B66B0D0 foreign key (parent_id)
references TEST_TL_PARENT
May 10, 2004 12:57:32 PM net.sf.hibernate.tool.hbm2ddl.SchemaExport execute
SEVERE: ORA-00942: table or view does not exist
May 10, 2004 12:57:32 PM net.sf.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: schema export complete
May 10, 2004 12:57:32 PM net.sf.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbc:oracle:oci8:@DEV
I am not sure whyis SchemaExport is trying to create duplicate columns for TEST_TL_CHILD table.
TIA
splash
|