My Java code...
Code:
public class Task {
private long id;
private String name;
private String code;
private Date expirationDate;
private List taskAttributes;
public Task() {
}
public String getCode() {
return code;
}
public Date getExpirationDate() {
return expirationDate;
}
public long getId() {
return id;
}
public String getName() {
return name;
}
public List getTaskAttributes() {
return taskAttributes;
}
public void setCode(String string) {
code = string;
}
public void setExpirationDate(Date date) {
expirationDate = date;
}
public void setId(long l) {
id = l;
}
public void setName(String string) {
name = string;
}
public void setTaskAttributes(List list) {
taskAttributes = list;
}
}
Code:
public class TaskAttribute {
private long id;
private Date expirationDate;
private Attribute attribute;
private Task task;
public TaskAttribute() {
}
public Attribute getAttribute() {
return attribute;
}
public Date getExpirationDate() {
return expirationDate;
}
public void setAttribute(Attribute attribute) {
this.attribute = attribute;
}
public void setExpirationDate(Date date) {
expirationDate = date;
}
public long getId() {
return id;
}
public Task getTask() {
return task;
}
public void setId(long l) {
id = l;
}
public void setTask(Task task) {
this.task = task;
}
}
Code:
public class Attribute {
private long id;
private String name;
private Date expirationDate;
public Attribute() {
}
public Date getExpirationDate() {
return expirationDate;
}
public long getId() {
return id;
}
public String getName() {
return name;
}
public void setExpirationDate(Date date) {
expirationDate = date;
}
public void setId(long l) {
id = l;
}
public void setName(String string) {
name = string;
}
}
My Test main class...
Code:
public class Test {
public static void main(String [] args) throws Exception {
Task task = new Task();
task.setName("cucho");
task.setCode("abc");
task.setExpirationDate(new Date(20040512));
Attribute attribute = new Attribute();
attribute.setName("cuchoAttribute");
attribute.setExpirationDate(new Date(20040512));
TaskAttribute taskAttribute = new TaskAttribute();
taskAttribute.setExpirationDate(new Date(20040512));
taskAttribute.setAttribute(attribute);
taskAttribute.setTask(task);
List taskAttributes = new ArrayList();
taskAttributes.add(taskAttribute);
task.setTaskAttributes(taskAttributes);
Configuration cfg = new Configuration().addClass(Task.class).addClass(TaskAttribute.class).addClass(Attribute.class);
SessionFactory sf = cfg.buildSessionFactory();
Session session = sf.openSession();
System.out.println("Saving instance");
session.saveOrUpdate(task);
System.out.println("Instance just saved");
}
}
My mapping files...
Quote:
<hibernate-mapping>
<class name="Task" table="tasks">
<id name="id" column="task_id" type="long" unsaved-value="null">
<generator class="hilo"/>
</id>
<property name="name" column="task_name" type="string" length="30" not-null="true"/>
<property name="code" column="task_code" type="string" length="30" not-null="true"/>
<property name="expirationDate" column="task_expirationDate" type="java.sql.Date" not-null="true"/>
<set name="taskAttributes" table="taskAttributes" cascade="all" inverse="true" lazy="true">
<key column="task_id"/>
<one-to-many class="TaskAttribute"/>
</set>
</class>
</hibernate-mapping>
Quote:
<hibernate-mapping>
<class name="TaskAttribute" table="taskAttributes">
<id name="id" column="taskAttribute_id" type="long" unsaved-value="null">
<generator class="hilo"/>
</id>
<property name="expirationDate" column="taskAttribute_expirationDate" type="java.sql.Date" not-null="true"/>
<many-to-one name="task" class="Task" column="task_id"/>
<one-to-one name="attribute" class="Attribute"/>
</class>
</hibernate-mapping>
Quote:
<hibernate-mapping>
<class name="Attribute" table="attributes">
<id name="id" column="attribute_id" type="long" unsaved-value="null">
<generator class="hilo"/>
</id>
<property name="name" column="attribute_name" type="string" length="30" not-null="true"/>
<property name="expirationDate" column="attribute_expirationDate" type="java.sql.Date" not-null="true"/>
</class>
</hibernate-mapping>
and the output when I run the test...
Quote:
blah blah... everything ok...
10:24:35,303 INFO SessionFactoryImpl:119 - building session factory
10:24:37,114 INFO SessionFactoryObjectFactory:82 - no JNDI name configured
10:24:37,150 INFO UpdateTimestampsCache:35 - starting update timestamps cache at region: net.sf.hibernate.cache.UpdateTimestampsCache
10:24:37,255 WARN Configurator:123 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/home/v910312/hibernateWorkspace/HibernateTest/lib/ehcache-0.7.jar!/ehcache-failsafe.xml
10:24:37,342 WARN Plugin:95 - Could not find configuration for net.sf.hibernate.cache.UpdateTimestampsCache. Configuring using the defaultCache settings.
10:24:37,446 INFO QueryCache:39 - starting query cache at region: net.sf.hibernate.cache.QueryCache
10:24:37,449 WARN Plugin:95 - Could not find configuration for net.sf.hibernate.cache.QueryCache. Configuring using the defaultCache settings.
Saving instance
Instance just saved
so... everything seems to be ok, i can connect to the db and create the tables using SchemeExport, etc, etc but when i check the tables in the database after executing the Test.java nothing is saved... they are all empty.
I'm not a DB specialist, so i neither don't know if the db desing is ok.
Thanks all for any possible hand !