-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate tools - Grundsätzliches Verständnisproblem
PostPosted: Tue Jun 13, 2006 11:35 am 
Regular
Regular

Joined: Mon May 22, 2006 8:32 am
Posts: 67
Hallo Forum,

ich habe eine generelle Frage zur Benutzung des reverse engeneering mit den Hibernate Tools. Ich möchte eine Tabelle meiner DB benutzen. Bei der automatischen Generierung bekomme ich folgende Dateien:

ViewGermanInternalsIdp.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 13.06.2006 16:10:55 by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
    <class name="de.wfm.generatedBOs.ViewGermanInternalsIdp" table="VIEW_GERMAN_INTERNALS_IDP" schema="dbo" catalog="ESDB">
        <composite-id name="id" class="de.wfm.generatedBOs.ViewGermanInternalsIdpId">
            <key-property name="surname" type="string">
                <column name="surname" length="40" />
            </key-property>
            <key-property name="firstname" type="string">
                <column name="firstname" length="40" />
            </key-property>
            <key-property name="peoplesoftId" type="java.lang.Integer">
                <column name="peoplesoft_id" />
            </key-property>
            <key-property name="empSk" type="big_decimal">
                <column name="emp_sk" precision="18" />
            </key-property>
            <key-property name="screenName" type="string">
                <column name="screen_name" length="60" />
            </key-property>
            <key-property name="swiftmail" type="string">
                <column name="swiftmail" length="40" />
            </key-property>
            <key-property name="inhouseLogin" type="string">
                <column name="inhouse_login" length="40" />
            </key-property>
            <key-property name="contractedHours" type="big_decimal">
                <column name="contracted_hours" precision="4" />
            </key-property>
            <key-property name="department" type="string">
                <column name="department" length="40" />
            </key-property>
            <key-property name="peoplesoftIdSupervisor" type="java.lang.Integer">
                <column name="peoplesoft_id_supervisor" />
            </key-property>
            <key-property name="peoplesoftIdManager" type="java.lang.Integer">
                <column name="peoplesoft_id_manager" />
            </key-property>
            <key-property name="location" type="string">
                <column name="location" length="40" />
            </key-property>
            <key-property name="active" type="boolean">
                <column name="active" />
            </key-property>
            <key-property name="startDate" type="timestamp">
                <column name="start_date" length="23" />
            </key-property>
            <key-property name="endDate" type="timestamp">
                <column name="end_date" length="23" />
            </key-property>
            <key-property name="directstaff" type="boolean">
                <column name="directstaff" />
            </key-property>
            <key-property name="isSupervisor" type="boolean">
                <column name="is_supervisor" />
            </key-property>
            <key-property name="isManager" type="boolean">
                <column name="is_manager" />
            </key-property>
        </composite-id>
    </class>
</hibernate-mapping>


ViewGermanInternalsIdp.java
Code:
package de.wfm.generatedBOs;

// Generated 13.06.2006 16:10:55 by Hibernate Tools 3.1.0.beta5

/**
* ViewGermanInternalsIdp generated by hbm2java
*/
public class ViewGermanInternalsIdp implements java.io.Serializable {

   // Fields   

   /**
    *
    */
   private static final long serialVersionUID = 1L;
   private ViewGermanInternalsIdpId id;

   // Constructors

   /** default constructor */
   public ViewGermanInternalsIdp() {
   }

   /** full constructor */
   public ViewGermanInternalsIdp(ViewGermanInternalsIdpId id) {
      this.id = id;
   }

   // Property accessors
   public ViewGermanInternalsIdpId getId() {
      return this.id;
   }

   public void setId(ViewGermanInternalsIdpId id) {
      this.id = id;
   }

}



ViewGermanInternalsIdpHome.java
Code:
package de.wfm.generatedBOs;

// Generated 13.06.2006 16:10:55 by Hibernate Tools 3.1.0.beta5

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.criterion.Example;

import de.wfm.dao.hibernateUtil.HibernateUtil;

/**
* Home object for domain model class ViewGermanInternalsIdp.
* @see de.wfm.generatedBOs.ViewGermanInternalsIdp
* @author Hibernate Tools
*/
public class ViewGermanInternalsIdpHome {

   private static final Log log = LogFactory
         .getLog(ViewGermanInternalsIdpHome.class);


   protected Session getCurrentSession() {
      return HibernateUtil.getSession(HibernateUtil.ESDB);
   }

   public void persist(ViewGermanInternalsIdp transientInstance) {
      log.debug("persisting ViewGermanInternalsIdp instance");
      try {
         getCurrentSession().persist(transientInstance);
         log.debug("persist successful");
      } catch (RuntimeException re) {
         log.error("persist failed", re);
         throw re;
      }
   }

   public void attachDirty(ViewGermanInternalsIdp instance) {
      log.debug("attaching dirty ViewGermanInternalsIdp instance");
      try {
         getCurrentSession().saveOrUpdate(instance);
         log.debug("attach successful");
      } catch (RuntimeException re) {
         log.error("attach failed", re);
         throw re;
      }
   }

   public void attachClean(ViewGermanInternalsIdp instance) {
      log.debug("attaching clean ViewGermanInternalsIdp instance");
      try {
         getCurrentSession().lock(instance, LockMode.NONE);
         log.debug("attach successful");
      } catch (RuntimeException re) {
         log.error("attach failed", re);
         throw re;
      }
   }

   public void delete(ViewGermanInternalsIdp persistentInstance) {
      log.debug("deleting ViewGermanInternalsIdp instance");
      try {
         getCurrentSession().delete(persistentInstance);
         log.debug("delete successful");
      } catch (RuntimeException re) {
         log.error("delete failed", re);
         throw re;
      }
   }

   public ViewGermanInternalsIdp merge(ViewGermanInternalsIdp detachedInstance) {
      log.debug("merging ViewGermanInternalsIdp instance");
      try {
         ViewGermanInternalsIdp result = (ViewGermanInternalsIdp) getCurrentSession().merge(detachedInstance);
         log.debug("merge successful");
         return result;
      } catch (RuntimeException re) {
         log.error("merge failed", re);
         throw re;
      }
   }

   public ViewGermanInternalsIdp findById(
         de.wfm.generatedBOs.ViewGermanInternalsIdpId id) {
      log.debug("getting ViewGermanInternalsIdp instance with id: " + id);
      try {
         ViewGermanInternalsIdp instance = (ViewGermanInternalsIdp) getCurrentSession().get(
                     "de.wfm.generatedBOs.ViewGermanInternalsIdp",
                     id);
         if (instance == null) {
            log.debug("get successful, no instance found");
         } else {
            log.debug("get successful, instance found");
         }
         return instance;
      } catch (RuntimeException re) {
         log.error("get failed", re);
         throw re;
      }
   }

   public List findByExample(ViewGermanInternalsIdp instance) {
      log.debug("finding ViewGermanInternalsIdp instance by example");
      try {
         List results = getCurrentSession().createCriteria(
               "de.wfm.generatedBOs.ViewGermanInternalsIdp").add(
               Example.create(instance)).list();
         log.debug("find by example successful, result size: "
               + results.size());
         return results;
      } catch (RuntimeException re) {
         log.error("find by example failed", re);
         throw re;
      }
   }
}



ViewGermanInternalsIdpId.java
Code:
package de.wfm.generatedBOs;

// Generated 13.06.2006 16:10:55 by Hibernate Tools 3.1.0.beta5

import java.math.BigDecimal;
import java.util.Date;

/**
* ViewGermanInternalsIdpId generated by hbm2java
*/
public class ViewGermanInternalsIdpId implements java.io.Serializable {

   // Fields   

   private String surname;

   private String firstname;

   private Integer peoplesoftId;

   private BigDecimal empSk;

   private String screenName;

   private String swiftmail;

   private String inhouseLogin;

   private BigDecimal contractedHours;

   private String department;

   private Integer peoplesoftIdSupervisor;

   private Integer peoplesoftIdManager;

   private String location;

   private boolean active;

   private Date startDate;

   private Date endDate;

   private boolean directstaff;

   private boolean isSupervisor;

   private boolean isManager;

   // Constructors

   /** default constructor */
   public ViewGermanInternalsIdpId() {
   }

   /** minimal constructor */
   public ViewGermanInternalsIdpId(String surname, String firstname,
         BigDecimal empSk, String screenName, String inhouseLogin,
         BigDecimal contractedHours, String department, String location,
         boolean active, Date startDate, boolean directstaff,
         boolean isSupervisor, boolean isManager) {
      this.surname = surname;
      this.firstname = firstname;
      this.empSk = empSk;
      this.screenName = screenName;
      this.inhouseLogin = inhouseLogin;
      this.contractedHours = contractedHours;
      this.department = department;
      this.location = location;
      this.active = active;
      this.startDate = startDate;
      this.directstaff = directstaff;
      this.isSupervisor = isSupervisor;
      this.isManager = isManager;
   }

   /** full constructor */
   public ViewGermanInternalsIdpId(String surname, String firstname,
         Integer peoplesoftId, BigDecimal empSk, String screenName,
         String swiftmail, String inhouseLogin, BigDecimal contractedHours,
         String department, Integer peoplesoftIdSupervisor,
         Integer peoplesoftIdManager, String location, boolean active,
         Date startDate, Date endDate, boolean directstaff,
         boolean isSupervisor, boolean isManager) {
      this.surname = surname;
      this.firstname = firstname;
      this.peoplesoftId = peoplesoftId;
      this.empSk = empSk;
      this.screenName = screenName;
      this.swiftmail = swiftmail;
      this.inhouseLogin = inhouseLogin;
      this.contractedHours = contractedHours;
      this.department = department;
      this.peoplesoftIdSupervisor = peoplesoftIdSupervisor;
      this.peoplesoftIdManager = peoplesoftIdManager;
      this.location = location;
      this.active = active;
      this.startDate = startDate;
      this.endDate = endDate;
      this.directstaff = directstaff;
      this.isSupervisor = isSupervisor;
      this.isManager = isManager;
   }

   // Property accessors
   public String getSurname() {
      return this.surname;
   }

   public void setSurname(String surname) {
      this.surname = surname;
   }

   public String getFirstname() {
      return this.firstname;
   }

   public void setFirstname(String firstname) {
      this.firstname = firstname;
   }

   public Integer getPeoplesoftId() {
      return this.peoplesoftId;
   }

   public void setPeoplesoftId(Integer peoplesoftId) {
      this.peoplesoftId = peoplesoftId;
   }

   public BigDecimal getEmpSk() {
      return this.empSk;
   }

   public void setEmpSk(BigDecimal empSk) {
      this.empSk = empSk;
   }

   public String getScreenName() {
      return this.screenName;
   }

   public void setScreenName(String screenName) {
      this.screenName = screenName;
   }

   public String getSwiftmail() {
      return this.swiftmail;
   }

   public void setSwiftmail(String swiftmail) {
      this.swiftmail = swiftmail;
   }

   public String getInhouseLogin() {
      return this.inhouseLogin;
   }

   public void setInhouseLogin(String inhouseLogin) {
      this.inhouseLogin = inhouseLogin;
   }

   public BigDecimal getContractedHours() {
      return this.contractedHours;
   }

   public void setContractedHours(BigDecimal contractedHours) {
      this.contractedHours = contractedHours;
   }

   public String getDepartment() {
      return this.department;
   }

   public void setDepartment(String department) {
      this.department = department;
   }

   public Integer getPeoplesoftIdSupervisor() {
      return this.peoplesoftIdSupervisor;
   }

   public void setPeoplesoftIdSupervisor(Integer peoplesoftIdSupervisor) {
      this.peoplesoftIdSupervisor = peoplesoftIdSupervisor;
   }

   public Integer getPeoplesoftIdManager() {
      return this.peoplesoftIdManager;
   }

   public void setPeoplesoftIdManager(Integer peoplesoftIdManager) {
      this.peoplesoftIdManager = peoplesoftIdManager;
   }

   public String getLocation() {
      return this.location;
   }

   public void setLocation(String location) {
      this.location = location;
   }

   public boolean isActive() {
      return this.active;
   }

   public void setActive(boolean active) {
      this.active = active;
   }

   public Date getStartDate() {
      return this.startDate;
   }

   public void setStartDate(Date startDate) {
      this.startDate = startDate;
   }

   public Date getEndDate() {
      return this.endDate;
   }

   public void setEndDate(Date endDate) {
      this.endDate = endDate;
   }

   public boolean isDirectstaff() {
      return this.directstaff;
   }

   public void setDirectstaff(boolean directstaff) {
      this.directstaff = directstaff;
   }

   public boolean isIsSupervisor() {
      return this.isSupervisor;
   }

   public void setIsSupervisor(boolean isSupervisor) {
      this.isSupervisor = isSupervisor;
   }

   public boolean isIsManager() {
      return this.isManager;
   }

   public void setIsManager(boolean isManager) {
      this.isManager = isManager;
   }

   public boolean equals(Object other) {
      if ((this == other))
         return true;
      if ((other == null))
         return false;
      if (!(other instanceof ViewGermanInternalsIdpId))
         return false;
      ViewGermanInternalsIdpId castOther = (ViewGermanInternalsIdpId) other;

      return ((this.getSurname() == castOther.getSurname()) || (this
            .getSurname() != null
            && castOther.getSurname() != null && this.getSurname().equals(
            castOther.getSurname())))
            && ((this.getFirstname() == castOther.getFirstname()) || (this
                  .getFirstname() != null
                  && castOther.getFirstname() != null && this
                  .getFirstname().equals(castOther.getFirstname())))
            && ((this.getPeoplesoftId() == castOther.getPeoplesoftId()) || (this
                  .getPeoplesoftId() != null
                  && castOther.getPeoplesoftId() != null && this
                  .getPeoplesoftId().equals(castOther.getPeoplesoftId())))
            && ((this.getEmpSk() == castOther.getEmpSk()) || (this
                  .getEmpSk() != null
                  && castOther.getEmpSk() != null && this.getEmpSk()
                  .equals(castOther.getEmpSk())))
            && ((this.getScreenName() == castOther.getScreenName()) || (this
                  .getScreenName() != null
                  && castOther.getScreenName() != null && this
                  .getScreenName().equals(castOther.getScreenName())))
            && ((this.getSwiftmail() == castOther.getSwiftmail()) || (this
                  .getSwiftmail() != null
                  && castOther.getSwiftmail() != null && this
                  .getSwiftmail().equals(castOther.getSwiftmail())))
            && ((this.getInhouseLogin() == castOther.getInhouseLogin()) || (this
                  .getInhouseLogin() != null
                  && castOther.getInhouseLogin() != null && this
                  .getInhouseLogin().equals(castOther.getInhouseLogin())))
            && ((this.getContractedHours() == castOther
                  .getContractedHours()) || (this.getContractedHours() != null
                  && castOther.getContractedHours() != null && this
                  .getContractedHours().equals(
                        castOther.getContractedHours())))
            && ((this.getDepartment() == castOther.getDepartment()) || (this
                  .getDepartment() != null
                  && castOther.getDepartment() != null && this
                  .getDepartment().equals(castOther.getDepartment())))
            && ((this.getPeoplesoftIdSupervisor() == castOther
                  .getPeoplesoftIdSupervisor()) || (this
                  .getPeoplesoftIdSupervisor() != null
                  && castOther.getPeoplesoftIdSupervisor() != null && this
                  .getPeoplesoftIdSupervisor().equals(
                        castOther.getPeoplesoftIdSupervisor())))
            && ((this.getPeoplesoftIdManager() == castOther
                  .getPeoplesoftIdManager()) || (this
                  .getPeoplesoftIdManager() != null
                  && castOther.getPeoplesoftIdManager() != null && this
                  .getPeoplesoftIdManager().equals(
                        castOther.getPeoplesoftIdManager())))
            && ((this.getLocation() == castOther.getLocation()) || (this
                  .getLocation() != null
                  && castOther.getLocation() != null && this
                  .getLocation().equals(castOther.getLocation())))
            && (this.isActive() == castOther.isActive())
            && ((this.getStartDate() == castOther.getStartDate()) || (this
                  .getStartDate() != null
                  && castOther.getStartDate() != null && this
                  .getStartDate().equals(castOther.getStartDate())))
            && ((this.getEndDate() == castOther.getEndDate()) || (this
                  .getEndDate() != null
                  && castOther.getEndDate() != null && this.getEndDate()
                  .equals(castOther.getEndDate())))
            && (this.isDirectstaff() == castOther.isDirectstaff())
            && (this.isIsSupervisor() == castOther.isIsSupervisor())
            && (this.isIsManager() == castOther.isIsManager());
   }

   public int hashCode() {
      int result = 17;

      result = 37 * result
            + (getSurname() == null ? 0 : this.getSurname().hashCode());
      result = 37 * result
            + (getFirstname() == null ? 0 : this.getFirstname().hashCode());
      result = 37
            * result
            + (getPeoplesoftId() == null ? 0 : this.getPeoplesoftId()
                  .hashCode());
      result = 37 * result
            + (getEmpSk() == null ? 0 : this.getEmpSk().hashCode());
      result = 37
            * result
            + (getScreenName() == null ? 0 : this.getScreenName()
                  .hashCode());
      result = 37 * result
            + (getSwiftmail() == null ? 0 : this.getSwiftmail().hashCode());
      result = 37
            * result
            + (getInhouseLogin() == null ? 0 : this.getInhouseLogin()
                  .hashCode());
      result = 37
            * result
            + (getContractedHours() == null ? 0 : this.getContractedHours()
                  .hashCode());
      result = 37
            * result
            + (getDepartment() == null ? 0 : this.getDepartment()
                  .hashCode());
      result = 37
            * result
            + (getPeoplesoftIdSupervisor() == null ? 0 : this
                  .getPeoplesoftIdSupervisor().hashCode());
      result = 37
            * result
            + (getPeoplesoftIdManager() == null ? 0 : this
                  .getPeoplesoftIdManager().hashCode());
      result = 37 * result
            + (getLocation() == null ? 0 : this.getLocation().hashCode());
      result = 37 * result + (this.isActive() ? 1 : 0);
      result = 37 * result
            + (getStartDate() == null ? 0 : this.getStartDate().hashCode());
      result = 37 * result
            + (getEndDate() == null ? 0 : this.getEndDate().hashCode());
      result = 37 * result + (this.isDirectstaff() ? 1 : 0);
      result = 37 * result + (this.isIsSupervisor() ? 1 : 0);
      result = 37 * result + (this.isIsManager() ? 1 : 0);
      return result;
   }

}



Meine Frage: Wie spielen diese Klassen zusammen? Was wird in welcher Klasse abgebildet?
Warum
ViewGermanInternalsIdp.java
und
ViewGermanInternalsIdpId.java?

Kann mich mal jemand aufklären? Würde es nicht reichen ein POJO "ViewGermanInternalsIdp.java" zu haben und mit dem DAO "ViewGermanInternalsIdpHome.java" dieses zu benutzen?
Warum ViewGermanInternalsIdpId.java?

Ich freue mich auf Erleuchtung! :)

Gruß,

a.k


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 14, 2006 3:27 am 
Beginner
Beginner

Joined: Fri May 19, 2006 11:34 am
Posts: 29
Die Erlauchtung soll dir zu teil werden.

Das Mapping-File beinhaltet eine <composite-id>. Das lässt darauf schliessen, dass sämtliche Attribute deiner Tabelle als primary gekennzeichnet sind. Und ein <composite-id> wird als eigenständige Klasse in Hibernate umgesetzt.

Du hast also eine Klasse ...Idp das ein Objekt der Klasse ...IdpID beinhaltet. Wenn du also in deinem Schema deinen Schlüssel minimierst (z.B. nur auf peoplesoft_id), was mit Sicherheit sinnvoll ist, sollte sich das auch geben.

Viele Grüsse
Kai


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 14, 2006 5:36 am 
Regular
Regular

Joined: Mon May 22, 2006 8:32 am
Posts: 67
Hallo Kai,

AlRudi wrote:
Die Erlauchtung soll dir zu teil werden.

Das Mapping-File beinhaltet eine <composite-id>. Das lässt darauf schliessen, dass sämtliche Attribute deiner Tabelle als primary gekennzeichnet sind. Und ein <composite-id> wird als eigenständige Klasse in Hibernate umgesetzt.

Du hast also eine Klasse ...Idp das ein Objekt der Klasse ...IdpID beinhaltet. Wenn du also in deinem Schema deinen Schlüssel minimierst (z.B. nur auf peoplesoft_id), was mit Sicherheit sinnvoll ist, sollte sich das auch geben.
Kai


Das war genau der Punkt. Ich habe die Standardeinstellungen des Reverseengeneering benutzt ohne Hibernate.reveng.xml zu benutzen. Ich habe dies korrigiert und nun eine Klasse mit dem besagten Schlüssel "peoplesoft_id".

Danke für die schnelle und hilfreiche Antwort.

Gruß,

Barntl


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

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.