-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Inheritance and Hibernate
PostPosted: Wed Apr 29, 2015 5:47 am 
Newbie

Joined: Sun Mar 29, 2015 3:28 pm
Posts: 3
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.