Hello everybody,
I have got the following question: is there any problem, if I make some parent class for some kind of mapping files? What I want is, that I don't need to write the same code many times. Here are some examples:
My AddsAdvertisement.java
Code:
package mapping.modules.exchange.advertisement.advertisement.action;
import java.util.*;
import mapping.infrastructure.action.ActionBase;
import mapping.infrastructure.action.util.*;
public class AddsAdvertisement extends ActionBase
{
public AddsAdvertisement() {}
public AddsAdvertisement(int id, Date actionTime, Ip actorIp, Set<DirectModification> modificationData)
{
super(modificationData, actorIp, actionTime, id);
}
}
My .hbm.xml File
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated 01.04.2015 22:07:57 by Hibernate Tools 4.3.1 -->
<hibernate-mapping>
<class name="mapping.modules.exchange.advertisement.advertisement.action.AddsAdvertisement" optimistic-lock="version" schema="public" table="adds_advertisement">
<id name="id" type="int">
<column name="id"/>
<generator class="sequence">
<param name="sequence">"adds_advertisement_id"</param>
</generator>
</id>
<property name="actionTime" type="timestamp">
<column length="29" name="action_time" not-null="true"/>
</property>
<property name="actorIp" type="mapping.infrastructure.action.util.IpUserType">
<column name="actor_ip" not-null="true"/>
</property>
<property name="modificationData" type="mapping.infrastructure.action.util.DirectModificationUserType">
<column name="modification_text" not-null="true"/>
</property>
</class>
</hibernate-mapping>
The parent class:
Code:
package mapping.infrastructure.action;
import java.util.*;
import mapping.infrastructure.action.util.*;
public class ActionBase
{
public ActionBase() {}
public ActionBase(Set<DirectModification> modificationData, Ip actorIp, Date actionTime, int id)
{
this.modificationData = modificationData;
this.actorIp = actorIp;
this.actionTime = actionTime;
this.id = id;
}
public Set<DirectModification> modificationData;
public Ip actorIp;
public Date actionTime;
public int id;
public Set<DirectModification> getModificationData() {
return modificationData;
}
public void setModificationData(Set<DirectModification> directModification) {
this.modificationData = directModification;
}
public Ip getActorIp()
{
return actorIp;
}
public void setActorIp(Ip actorIp)
{
this.actorIp = actorIp;
}
public Date getActionTime()
{
return actionTime;
}
public void setActionTime(Date actionTime)
{
this.actionTime = actionTime;
}
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
}
Will does work? If not, are there any solutions?