Dobry den,
V pripade hibernate uspesne pouzivam HibernateSync plugin do eclipsu. Z
hbm.xml generuje 'Base' value objekty, ktore su abstraktne ale je v nich
vsetko co sa da z hbm vygenerovat. Dalej sa generuju uz konkretne value
objekty ktore extenduju tieto 'Base' objekty. Tam uz patri dodatocna
funkcionalita a tieto konkretne objekty sa ukladaju do DB. HibernateSync
sa samozrejme stara o to aby konkretne objekty neboli pregenerovane.
Priklad tychto generovanych objektov prikladam v prilohe.
Martin Krajci
Tomáš Procházka wrote:
Ahoj,
odpovídám na zprávu z úterka, 19. září 2006,
kterou Martin Krajci napsal(a) v 9:25:39:
M> Suhlasim s vami ze JPA je pohodlnejsie avsak pre Hibernate v sucasnosti
M> existuje uz vela toolov (pluginov) ktore zjednodusuju aj tvorbu hbm.xml
No, právě, je toho tolik, že se mi do toho nikdy nechtělo ;-)
Teď to mám hezky po ruce.
M> Tiez by sa dalo pisat o tom co je lepsie ci anotacie alebo xml
M> deployment descriptory. Podla mna to zavisi od tipu projektu, aky
M> pristup zvolite. Pre male projekty na ktorych pracuje malo ludi sa hodia
M> anotacie. Pre velke projekty by som volil xml aby bolo vsetko na jednom
M> mieste a nie rozhadzane po kode.
To je asi pravda, ale zase se musí hlídat, aby programátoři udrželi ty POJO
třídy konzistentní s těmi XML. Teda pokud se ty třídy negenerují automaticky z
toho XML, což mě přivádí k jednomu dotazu. A to, zda je dobře ty entitní třídy
upravovat a doplňovat o další funkcionalitu, tím se ztratí možnost je pak
snadno přegenerovat. Napadlo mě udělat potomka a rozšiřovat jej, ale nevím, jak
to pak bude fungovat, všude se píše, že potomci se dělají v případě, že chci
mít podentitu, tedy že to ve výsledku bude ve dvou tabulkách s vazbou 1:1, což
ale nechci. Jak se to tedy správně dělá?
M> Na JPA sa mne paci ze je to standard a tak ako pod hibernate mozete
M> relativne jednoducho zmenit databazu tak pod JPA mozete zmenit
M> perzistencneho vendora.
Ano, to se mi na tom líbí.
--------------------------- Původní zpráva ---------------------------
Odesilatel: Martin Krajci <[EMAIL PROTECTED]>
Předmět: JPA a Hibernate
Datum: 19. září 2006, 09:25:39 (GMT +0200)
Přílohy: <none>
msgid:[EMAIL PROTECTED]
.
------------------------ Konec původní zprávy ------------------------
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________package sk.krajci.mvp.business.vo.base;
import java.io.Serializable;
/**
* This class has been automatically generated by Hibernate Synchronizer.
* For more information or documentation, visit The Hibernate Synchronizer page
* at http://www.binamics.com/hibernatesync or contact Joe Hudson at [EMAIL
PROTECTED]
*
* This is an object that contains data related to the person table.
* Do not modify this class because it will be overwritten if the configuration
file
* related to this class is modified.
*
* @hibernate.class
* table="person"
*/
public abstract class BasePerson implements Serializable, Cloneable {
public static String PROP_PASSWORD = "password";
public static String PROP_NAME = "name";
public static String PROP_ID = "id";
private int hashCode = Integer.MIN_VALUE;
// primary key
private java.lang.Integer _id;
// fields
private java.lang.String _name;
private java.lang.String _password;
// collections
private java.util.Set _rolesInternal;
// constructors
public BasePerson () {
initialize();
}
/**
* Constructor for primary key
*/
public BasePerson (java.lang.Integer _id) {
this.setId(_id);
initialize();
}
/**
* Constructor for required fields
*/
public BasePerson (
java.lang.Integer _id,
java.lang.String _name,
java.lang.String _password) {
this.setId(_id);
this.setName(_name);
this.setPassword(_password);
initialize();
}
protected void initialize () {}
/**
* Return the unique identifier of this class
* @hibernate.id
* generator-class="identity"
* column="id"
*/
public java.lang.Integer getId () {
return _id;
}
/**
* Set the unique identifier of this class
* @param _id the new ID
*/
public void setId (java.lang.Integer _id) {
this._id = _id;
this.hashCode = Integer.MIN_VALUE;
}
/**
* Return the value associated with the column: name
*/
public java.lang.String getName () {
return _name;
}
/**
* Set the value related to the column: name
* @param _name the name value
*/
public void setName (java.lang.String _name) {
this._name = _name;
}
/**
* Return the value associated with the column: password
*/
public java.lang.String getPassword () {
return _password;
}
/**
* Set the value related to the column: password
* @param _password the password value
*/
public void setPassword (java.lang.String _password) {
this._password = _password;
}
/**
* Return the value associated with the column: rolesInternal
*/
public java.util.Set getRolesInternal () {
return this._rolesInternal;
}
/**
* Set the value related to the column: rolesInternal
* @param _rolesInternal the rolesInternal value
*/
public void setRolesInternal (java.util.Set _rolesInternal) {
this._rolesInternal = _rolesInternal;
}
public void addToRolesInternal (Object obj) {
if (null == this._rolesInternal) this._rolesInternal = new
java.util.HashSet();
this._rolesInternal.add(obj);
}
public boolean equals (Object obj) {
if (null == obj) return false;
if (!(obj instanceof
sk.krajci.mvp.business.vo.base.BasePerson)) return false;
else {
sk.krajci.mvp.business.vo.base.BasePerson mObj =
(sk.krajci.mvp.business.vo.base.BasePerson) obj;
if (null == this.getId() || null == mObj.getId())
return false;
else return (this.getId().equals(mObj.getId()));
}
}
public int hashCode () {
if (Integer.MIN_VALUE == this.hashCode) {
if (null == this.getId()) return super.hashCode();
else {
String hashStr = this.getClass().getName() +
":" + this.getId().hashCode();
this.hashCode = hashStr.hashCode();
}
}
return this.hashCode;
}
public String toString () {
return
org.apache.commons.lang.builder.ToStringBuilder.reflectionToString(this);
}
public Object clone() {
Object o = null;
try {
o = super.clone();
}
catch (CloneNotSupportedException ex) {
throw new InternalError();
}
return o;
}
}package sk.krajci.mvp.business.vo;
/**
* This class has been automatically generated by Hibernate Synchronizer.
* For more information or documentation, visit The Hibernate Synchronizer page
* at http://www.binamics.com/hibernatesync or contact Joe Hudson at [EMAIL
PROTECTED]
*/
public interface IPerson extends IGeneralVO {
public java.lang.String getPassword ();
public void setPassword (java.lang.String _password);
public java.lang.String getName ();
public void setName (java.lang.String _name);
public java.lang.Integer getId ();
public void setId (java.lang.Integer _id);
}package sk.krajci.mvp.business.vo;
import sk.krajci.mvp.business.vo.base.BasePerson;
/**
* This is the object class that relates to the person table.
* Any customizations belong here.
*/
public class Person extends BasePerson implements IPerson {
/*[CONSTRUCTOR MARKER BEGIN]*/
public Person () {
super();
}
/**
* Constructor for primary key
*/
public Person (java.lang.Integer _id) {
super(_id);
}
/**
* Constructor for required fields
*/
public Person (
java.lang.Integer _id,
java.lang.String _name,
java.lang.String _password) {
super (
_id,
_name,
_password);
}
/*[CONSTRUCTOR MARKER END]*/
}