Hibernate version:3
I have un problem with composites key's
Is composite work properly ,
My Model: article, categorie, art_cat
art_cat is a link table
article =====art_cat=======categorie
When i load 1 article + set 1 or more art_cat no pb
If i create a new "article", create 1 new art_cat hibernate send
insert into art_cat (art_id, cat_id) values (NULL, 1)
there no update of art_id
Is any body see somthing wrong ?
Hibernate: select nextval ('article_art_id_seq')
Hibernate: select artcat_.art_id, artcat_.cat_id from art_cat artcat_ where artcat_.art_id=? and artcat_.cat_id=?
insert Article ID: 30);
Hibernate: insert into article (art_code, art_lib1, art_lib2, art_lib3, art_lib4, art_cmt, art_ht, art_ttc, art_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into art_cat (art_id, cat_id) values (?, ?)
oct. 27 14:49:00 ERROR [http-8080-Processor25] util.JDBCExceptionReporter - L'élément du batch 0 insert into art_cat (art_id, cat_id) values (NULL, 1) a été annulé. Appeler getNextException pour en connaître la cause.
oct. 27 14:49:00 ERROR [http-8080-Processor25] util.JDBCExceptionReporter - ERROR: null value in column "art_id" violates not-null constraint
oct. 27 14:49:00 ERROR [http-8080-Processor25] def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
CREATE TABLE article
(
art_id int4 NOT NULL DEFAULT nextval('public.gc_art_art_id_seq'::text),
art_code varchar(60) NOT NULL,
art_lib1 varchar(60) NOT NULL,
art_lib2 varchar(60),
art_lib3 varchar(60),
art_lib4 varchar(60),
art_cmt text,
art_ht numeric(10,2) NOT NULL,
art_ttc numeric(10,2) NOT NULL,
CONSTRAINT pk_gc_art PRIMARY KEY (art_id)
)
CREATE TABLE categorie
(
cat_id serial NOT NULL,
cat_lib varchar(60) NOT NULL,
CONSTRAINT pk_categorie PRIMARY KEY (cat_id)
)
CREATE TABLE art_cat
(
art_id int4 NOT NULL,
cat_id int4 NOT NULL,
CONSTRAINT pk_art_cat PRIMARY KEY (art_id, cat_id),
CONSTRAINT fk_art_cat_reference_article FOREIGN KEY (art_id) REFERENCES article (art_id) ON UPDATE RESTRICT ON DELETE RESTRICT,
CONSTRAINT fk_art_cat_reference_categori FOREIGN KEY (cat_id) REFERENCES categorie (cat_id) ON UPDATE RESTRICT ON DELETE RESTRICT
)
config files :
//**********************************************
//***Article.hbm.xml***
//**********************************************
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<!-- Created by the Matta generator hibernate mapping -->
<!-- genere par HBXMLWriter.java -->
<class name="app.hb.Article" table="article">
<id
name="art_id"
type="java.lang.Integer"
column="art_id"
unsaved-value="null"
>
<generator class="native" >
<param name="sequence">article_art_id_seq</param>
</generator>
</id>
<property
name="art_code"
type="java.lang.String"
column="art_code"
not-null="true"
length="60"
/>
<property
name="art_lib1"
type="java.lang.String"
column="art_lib1"
not-null="true"
length="60"
/>
<property
name="art_lib2"
type="java.lang.String"
column="art_lib2"
not-null="false"
length="60"
/>
<property
name="art_lib3"
type="java.lang.String"
column="art_lib3"
not-null="false"
length="60"
/>
<property
name="art_lib4"
type="java.lang.String"
column="art_lib4"
not-null="false"
length="60"
/>
<property
name="art_cmt"
type="java.lang.String"
column="art_cmt"
not-null="false"
length="-1"
/>
<property
name="art_ht"
type="java.math.BigDecimal"
column="art_ht"
not-null="true"
length="10"
/>
<property
name="art_ttc"
type="java.math.BigDecimal"
column="art_ttc"
not-null="true"
length="10"
/>
<!-- bi-directional one-to-many article to art_cat -->
<set
name="art_cat_art_ids"
lazy="false"
inverse="true"
cascade="all-delete-orphan"
>
<key>
<column name="art_id" />
</key>
<one-to-many
class="app.hb.ArtCat"
/>
</set>
<!-- bi-directional one-to-many article to facture_ligne -->
<set
name="facture_ligne_art_ids"
lazy="false"
inverse="true"
cascade="all-delete-orphan"
>
<key>
<column name="art_id" />
</key>
<one-to-many
class="app.hb.FactureLigne"
/>
</set>
</class>
</hibernate-mapping>
//**********************************************
//***Categorie.hbm.xml***
//**********************************************
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<!-- Created by the Matta generator hibernate mapping -->
<!-- genere par HBXMLWriter.java -->
<class name="app.hb.Categorie" table="categorie">
<id
name="cat_id"
type="java.lang.Integer"
column="cat_id"
unsaved-value="null"
>
<generator class="native" >
<param name="sequence">categorie_cat_id_seq</param>
</generator>
</id>
<property
name="cat_lib"
type="java.lang.String"
column="cat_lib"
not-null="true"
length="60"
/>
</class>
</hibernate-mapping>
//**********************************************
//***ArtCat.hbm.xml***
//**********************************************
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<!-- Created by the Matta generator hibernate mapping -->
<!-- genere par HBXMLWriter.java -->
<class name="app.hb.ArtCat" table="art_cat">
<composite-id name="comp_id" class="app.hb.ArtCatPK">
<key-property
name="art_id"
column="art_id"
type="java.lang.Integer"
length="4"
/>
<key-property
name="cat_id"
column="cat_id"
type="java.lang.Integer"
length="4"
/>
</composite-id>
<!--bi-directional many-to-one art_cat to article -->
<many-to-one
name="article_art_id"
class="app.hb.Article"
not-null="true"
update="false"
insert="false"
lazy="false"
>
<column name="art_id" />
</many-to-one>
<!--bi-directional many-to-one art_cat to categorie -->
<many-to-one
name="categorie_cat_id"
class="app.hb.Categorie"
not-null="true"
update="false"
insert="false"
lazy="false"
>
<column name="cat_id" />
</many-to-one>
</class>
</hibernate-mapping>
//**********************************************
//***3 POJOs***
//**********************************************
//**********************************************
//***Article.java***
//**********************************************
/*************************************
* Copyright : Copyright (c) 2005
* Société : i-programmes
* @author D. MATTASOGLIO
* @version 1.0
* genere par HBPOJOWriter.java
*
* POJO pour HB
**************************************/
package app.hb;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import app.parametre.*;
import app.entite.*;
import java.util.Iterator;
// imports+
// imports-
public class Article implements Serializable
{
// Declaration des variables classiques
// Pour les float et date tel que montant ou date declaration du sup et inf
// pour les recherches par intervalles
private Integer art_id;
private Integer art_id_inf;
private Integer art_id_sup;
private String art_code;
private String art_lib1;
private String art_lib2;
private String art_lib3;
private String art_lib4;
private String art_cmt;
// Pour les float et date tel que montant ou date declaration du sup et inf
// pour les recherches par intervalles
private java.math.BigDecimal art_ht;
private java.math.BigDecimal art_ht_inf;
private java.math.BigDecimal art_ht_sup;
// Pour les float et date tel que montant ou date declaration du sup et inf
// pour les recherches par intervalles
private java.math.BigDecimal art_ttc;
private java.math.BigDecimal art_ttc_inf;
private java.math.BigDecimal art_ttc_sup;
// Declaration des variables de classes issues des FK
// Many to One
// Declaration des set One to Many
// Declaration des set : pk de la table courante fk pour les autres
private Set art_cat_art_ids ;
private Set facture_ligne_art_ids ;
// **** Relation MANY to MANY
private int[] int_art_cat_art_id ;
/********************************************
* Constructeur de classe avec initialisation.
********************************************/
public Article(
Integer art_id
,Integer art_id_inf
,Integer art_id_sup
,String art_code
,String art_lib1
,String art_lib2
,String art_lib3
,String art_lib4
,String art_cmt
,java.math.BigDecimal art_ht
,java.math.BigDecimal art_ht_inf
,java.math.BigDecimal art_ht_sup
,java.math.BigDecimal art_ttc
,java.math.BigDecimal art_ttc_inf
,java.math.BigDecimal art_ttc_sup
,Set art_cat_art_ids
,Set facture_ligne_art_ids
)
{
this.art_id=art_id;
this.art_id_inf=art_id_inf;
this.art_id_sup=art_id_sup;
this.art_code = art_code;
this.art_lib1 = art_lib1;
this.art_lib2 = art_lib2;
this.art_lib3 = art_lib3;
this.art_lib4 = art_lib4;
this.art_cmt = art_cmt;
this.art_ht=art_ht;
this.art_ht_inf=art_ht_inf;
this.art_ht_sup=art_ht_sup;
this.art_ttc=art_ttc;
this.art_ttc_inf=art_ttc_inf;
this.art_ttc_sup=art_ttc_sup;
this.art_cat_art_ids = art_cat_art_ids ;
this.facture_ligne_art_ids = facture_ligne_art_ids ;
}
/********************************************
* Constructeur de classe avec initialisation minimal .
********************************************/
public Article(
Integer art_id
,Integer art_id_inf
,Integer art_id_sup
,String art_code
,String art_lib1
,java.math.BigDecimal art_ht
,java.math.BigDecimal art_ht_inf
,java.math.BigDecimal art_ht_sup
,java.math.BigDecimal art_ttc
,java.math.BigDecimal art_ttc_inf
,java.math.BigDecimal art_ttc_sup
// Variables issues de FK
,Set art_cat_art_ids
,Set facture_ligne_art_ids
)
{
this.art_id=art_id;
this.art_id_inf=art_id_inf;
this.art_id_sup=art_id_sup;
this.art_code = art_code;
this.art_lib1 = art_lib1;
this.art_ht=art_ht;
this.art_ht_inf=art_ht_inf;
this.art_ht_sup=art_ht_sup;
this.art_ttc=art_ttc;
this.art_ttc_inf=art_ttc_inf;
this.art_ttc_sup=art_ttc_sup;
this.art_cat_art_ids = art_cat_art_ids ;
this.facture_ligne_art_ids = facture_ligne_art_ids ;
}
/*********************************************
* Constructeur de classe initialisation a vide
*********************************************/
public Article()
{}
/********************************************
* Flux XML.
* Param header header de version xml
********************************************/
public String get_fullxml(boolean header)
{
StringBuffer sbXML = new StringBuffer();
if (header) sbXML.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
sbXML.append("<article>");
sbXML.append("<art_id>");sbXML.append( getart_id());sbXML.append("</art_id>\n");
sbXML.append("<art_code>");sbXML.append( getart_code());sbXML.append("</art_code>\n");
sbXML.append("<art_lib1>");sbXML.append( getart_lib1());sbXML.append("</art_lib1>\n");
sbXML.append("<art_lib2>");sbXML.append( getart_lib2());sbXML.append("</art_lib2>\n");
sbXML.append("<art_lib3>");sbXML.append( getart_lib3());sbXML.append("</art_lib3>\n");
sbXML.append("<art_lib4>");sbXML.append( getart_lib4());sbXML.append("</art_lib4>\n");
sbXML.append("<art_cmt>");sbXML.append( getart_cmt());sbXML.append("</art_cmt>\n");
sbXML.append("<art_ht>");sbXML.append( getart_ht());sbXML.append("</art_ht>\n");
sbXML.append("<art_ttc>");sbXML.append( getart_ttc());sbXML.append("</art_ttc>\n");
Iterator iter;
iter = this.art_cat_art_ids.iterator();
while ( iter.hasNext() )
{
ArtCat iArtCat= (ArtCat)iter.next();
sbXML.append(iArtCat.get_xml(false));
}
iter = this.facture_ligne_art_ids.iterator();
while ( iter.hasNext() )
{
FactureLigne iFactureLigne= (FactureLigne)iter.next();
sbXML.append(iFactureLigne.get_xml(false));
}
sbXML.append("</article>");
return sbXML.toString();
}
/********************************************
* Flux XML.
* Param header header de version xml
********************************************/
public String get_xml(boolean header)
{
StringBuffer sbXML = new StringBuffer();
if (header) sbXML.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n");
sbXML.append("<article>");
sbXML.append("<art_id>");sbXML.append( getart_id());sbXML.append("</art_id>\n");
sbXML.append("<art_code>");sbXML.append( getart_code());sbXML.append("</art_code>\n");
sbXML.append("<art_lib1>");sbXML.append( getart_lib1());sbXML.append("</art_lib1>\n");
sbXML.append("<art_lib2>");sbXML.append( getart_lib2());sbXML.append("</art_lib2>\n");
sbXML.append("<art_lib3>");sbXML.append( getart_lib3());sbXML.append("</art_lib3>\n");
sbXML.append("<art_lib4>");sbXML.append( getart_lib4());sbXML.append("</art_lib4>\n");
sbXML.append("<art_cmt>");sbXML.append( getart_cmt());sbXML.append("</art_cmt>\n");
sbXML.append("<art_ht>");sbXML.append( getart_ht());sbXML.append("</art_ht>\n");
sbXML.append("<art_ttc>");sbXML.append( getart_ttc());sbXML.append("</art_ttc>\n");
sbXML.append("</article>");
return sbXML.toString();
}
/**
* Getter methode : art_id.
*/
public Integer getart_id()
{ return art_id; }
public Integer getart_id_inf()
{ return art_id_inf; }
public Integer getart_id_sup()
{ return art_id_sup; }
/**
* Setter methode : art_id.
*/
public void setart_id(Integer newVal)
{this.art_id = newVal; }
public void setart_id_inf(Integer newVal)
{this.art_id_inf = newVal; }
public void setart_id_sup(Integer newVal)
{this.art_id_sup = newVal; }
/**
* Getter methode : art_code.
*/
public String getart_code()
{ return art_code; }
/**
* Setter methode : art_code.
*/
public void setart_code(String newVal)
{this.art_code = newVal; }
/**
* Getter methode : art_lib1.
*/
public String getart_lib1()
{ return art_lib1; }
/**
* Setter methode : art_lib1.
*/
public void setart_lib1(String newVal)
{this.art_lib1 = newVal; }
/**
* Getter methode : art_lib2.
*/
public String getart_lib2()
{ return art_lib2; }
/**
* Setter methode : art_lib2.
*/
public void setart_lib2(String newVal)
{this.art_lib2 = newVal; }
/**
* Getter methode : art_lib3.
*/
public String getart_lib3()
{ return art_lib3; }
/**
* Setter methode : art_lib3.
*/
public void setart_lib3(String newVal)
{this.art_lib3 = newVal; }
/**
* Getter methode : art_lib4.
*/
public String getart_lib4()
{ return art_lib4; }
/**
* Setter methode : art_lib4.
*/
public void setart_lib4(String newVal)
{this.art_lib4 = newVal; }
/**
* Getter methode : art_cmt.
*/
public String getart_cmt()
{ return art_cmt; }
/**
* Setter methode : art_cmt.
*/
public void setart_cmt(String newVal)
{this.art_cmt = newVal; }
/**
* Getter methode : art_ht.
*/
public java.math.BigDecimal getart_ht()
{ return art_ht; }
public java.math.BigDecimal getart_ht_inf()
{ return art_ht_inf; }
public java.math.BigDecimal getart_ht_sup()
{ return art_ht_sup; }
/**
* Setter methode : art_ht.
*/
public void setart_ht(java.math.BigDecimal newVal)
{this.art_ht = newVal; }
public void setart_ht_inf(java.math.BigDecimal newVal)
{this.art_ht_inf = newVal; }
public void setart_ht_sup(java.math.BigDecimal newVal)
{this.art_ht_sup = newVal; }
/**
* Getter methode : art_ttc.
*/
public java.math.BigDecimal getart_ttc()
{ return art_ttc; }
public java.math.BigDecimal getart_ttc_inf()
{ return art_ttc_inf; }
public java.math.BigDecimal getart_ttc_sup()
{ return art_ttc_sup; }
/**
* Setter methode : art_ttc.
*/
public void setart_ttc(java.math.BigDecimal newVal)
{this.art_ttc = newVal; }
public void setart_ttc_inf(java.math.BigDecimal newVal)
{this.art_ttc_inf = newVal; }
public void setart_ttc_sup(java.math.BigDecimal newVal)
{this.art_ttc_sup = newVal; }
/**
* Getter methode :
*/
public Set getart_cat_art_ids ()
{
return this.art_cat_art_ids;
}
/**
* Setter methode :
*/
public void setart_cat_art_ids (Set newval )
{
this.art_cat_art_ids = newval ;
}
/**
* Getter methode :
*/
public Set getfacture_ligne_art_ids ()
{
return this.facture_ligne_art_ids;
}
/**
* Setter methode :
*/
public void setfacture_ligne_art_ids (Set newval )
{
this.facture_ligne_art_ids = newval ;
}
//***********************************
// **** Relation MANY to MANY
//***********************************
public int[] getint_art_cat_art_id()
{
java.util.Set set = (java.util.Set) this.getart_cat_art_ids();
if (set == null || set.size() <= 0 ) return null;
int_art_cat_art_id = new int[set.size()];
Iterator iter = set.iterator();
int i=0;
while ( iter.hasNext() )
{
ArtCat lArtCat=(ArtCat)iter.next();
if (lArtCat!= null && lArtCat.getComp_id() != null && lArtCat.getComp_id().getcat_id().intValue() > 0 )
{int_art_cat_art_id[i] = lArtCat.getComp_id().getcat_id().intValue(); i++;}
}
return int_art_cat_art_id;
}
public void setint_art_cat_art_id(int[] newval)
{
int_art_cat_art_id = newval;
if (art_cat_art_ids == null) art_cat_art_ids = new HashSet();
art_cat_art_ids.clear();
for (int j =0 ; j < newval.length ; j++)
{
if (this.art_id != null && this.art_id.intValue()== 0) this.art_id = null;
ArtCatPK lArtCatPK= new ArtCatPK(this.art_id, new Integer (newval[j]));
ArtCat lArtCat= new ArtCat( lArtCatPK, this , ( new CategorieBD().load(new Integer (newval[j]))));
this.art_cat_art_ids.add(lArtCat);
}
}
// Implementation de la methode toString()
public String toString() {
return new ToStringBuilder(this)
.append("art_id", getart_id())
.toString();
}
/*********************************
* Insert de l objet par le BD (Business Delegate)
*/
public Integer insert()
{
//Initialisation du bean de base de donne par rapport a cet objet (BK)
ArticleBD iArticleBD = new ArticleBD(this);
this.art_id= iArticleBD.insert() ;
return this.art_id;
}
/*********************************
* Update de l objet par le BD (Business Delegate)
*/
public String update()
{
//Initialisation du bean de base de donne par rapport a cet objet (BK)
ArticleBD iArticleBD = new ArticleBD(this);
return iArticleBD.update() ;
}
/*********************************
* Delete de l objet par le BD (Business Delegate)
*/
public String delete()
{
//Initialisation du bean de base de donne par rapport a cet objet (BK)
ArticleBD iArticleBD = new ArticleBD(this);
return iArticleBD.delete() ;
}
/*********************************
* Construction de la clause WHERE
*/
public String getWhereClause()
{
String WhereClause= "";
if (this.art_id != null )
if (WhereClause.equalsIgnoreCase(""))
WhereClause += " WHERE art_id = "+this.art_id;
else
WhereClause += " AND art_id = "+this.art_id;
if (this.art_code != null && !this.art_code.trim().equalsIgnoreCase(""))
if (WhereClause.equalsIgnoreCase(""))
WhereClause += " WHERE art_code like '%"+this.art_code+"%'";
else
WhereClause += " AND art_code like '%"+this.art_code+"%'";
if (this.art_lib1 != null && !this.art_lib1.trim().equalsIgnoreCase(""))
if (WhereClause.equalsIgnoreCase(""))
WhereClause += " WHERE art_lib1 like '%"+this.art_lib1+"%'";
else
WhereClause += " AND art_lib1 like '%"+this.art_lib1+"%'";
if (this.art_lib2 != null && !this.art_lib2.trim().equalsIgnoreCase(""))
if (WhereClause.equalsIgnoreCase(""))
WhereClause += " WHERE art_lib2 like '%"+this.art_lib2+"%'";
else
WhereClause += " AND art_lib2 like '%"+this.art_lib2+"%'";
if (this.art_lib3 != null && !this.art_lib3.trim().equalsIgnoreCase(""))
if (WhereClause.equalsIgnoreCase(""))
WhereClause += " WHERE art_lib3 like '%"+this.art_lib3+"%'";
else
WhereClause += " AND art_lib3 like '%"+this.art_lib3+"%'";
if (this.art_lib4 != null && !this.art_lib4.trim().equalsIgnoreCase(""))
if (WhereClause.equalsIgnoreCase(""))
WhereClause += " WHERE art_lib4 like '%"+this.art_lib4+"%'";
else
WhereClause += " AND art_lib4 like '%"+this.art_lib4+"%'";
if (this.art_cmt != null && !this.art_cmt.trim().equalsIgnoreCase(""))
if (WhereClause.equalsIgnoreCase(""))
WhereClause += " WHERE art_cmt like '%"+this.art_cmt+"%'";
else
WhereClause += " AND art_cmt like '%"+this.art_cmt+"%'";
if (this.art_ht != null )
if (WhereClause.equalsIgnoreCase(""))
WhereClause += " WHERE art_ht = "+this.art_ht;
else
WhereClause += " AND art_ht = "+this.art_ht;
if (this.art_ht_inf != null )
if (WhereClause.equalsIgnoreCase(""))
WhereClause += " WHERE art_ht >= "+this.art_ht_inf+"";
else
WhereClause += " AND art_ht >= "+this.art_ht_inf+"";
if (this.art_ht_sup != null )
if (WhereClause.equalsIgnoreCase(""))
WhereClause += " WHERE art_ht <= "+this.art_ht_sup+"";
else
WhereClause += " AND art_ht <= "+this.art_ht_sup+"";
if (this.art_ttc != null )
if (WhereClause.equalsIgnoreCase(""))
WhereClause += " WHERE art_ttc = "+this.art_ttc;
else
WhereClause += " AND art_ttc = "+this.art_ttc;
if (this.art_ttc_inf != null )
if (WhereClause.equalsIgnoreCase(""))
WhereClause += " WHERE art_ttc >= "+this.art_ttc_inf+"";
else
WhereClause += " AND art_ttc >= "+this.art_ttc_inf+"";
if (this.art_ttc_sup != null )
if (WhereClause.equalsIgnoreCase(""))
WhereClause += " WHERE art_ttc <= "+this.art_ttc_sup+"";
else
WhereClause += " AND art_ttc <= "+this.art_ttc_sup+"";
return WhereClause;
}
}
//**********************************************
//***Categorie.java***
//**********************************************
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<!-- Created by the Matta generator hibernate mapping -->
<!-- genere par HBXMLWriter.java -->
<class name="app.hb.Categorie" table="categorie">
<id
name="cat_id"
type="java.lang.Integer"
column="cat_id"
unsaved-value="null"
>
<generator class="native" >
<param name="sequence">categorie_cat_id_seq</param>
</generator>
</id>
<property
name="cat_lib"
type="java.lang.String"
column="cat_lib"
not-null="true"
length="60"
/>
</class>
</hibernate-mapping>
//**********************************************
//***ArtCat.java***
//**********************************************
/*************************************
* Copyright : Copyright (c) 2005
* Société : i-programmes
* @author D. MATTASOGLIO
* @version 1.0
* généré par HBPOJOLIENWriter.java
* POJO LIEN pour HB
**************************************/
package app.hb;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import app.parametre.*;
import app.entite.*;
import java.util.Iterator;
// imports+
// imports-
public class ArtCat implements Serializable
{
// Pas de Declaration des variables classiques
// Declaration des variables classiques
private app.hb.Article article_art_id;
private app.hb.Categorie categorie_cat_id;
private app.hb.ArtCatPK comp_id;
/********************************************
* Constructeur de classe avec initialisation.
********************************************/
public ArtCat(
app.hb.ArtCatPK comp_id
,app.hb.Article article_art_id
,app.hb.Categorie categorie_cat_id
)
{
this.comp_id = comp_id;
this.article_art_id = article_art_id;
this.categorie_cat_id = categorie_cat_id;
}
/********************************************
* Constructeur de classe avec initialisation minimal .
********************************************/
public ArtCat(
app.hb.ArtCatPK comp_id
)
{ this.comp_id = comp_id;
}
/*********************************************
* Constructeur de classe initialisation a vide
*********************************************/
public ArtCat()
{}
/********************************************
* Flux XML.
* Param header header de version xml
********************************************/
public String get_xml(boolean header)
{
StringBuffer sbXML = new StringBuffer();
if (header) sbXML.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
sbXML.append("<artcat>");
// Flux a faire a la main trop complex
sbXML.append("</artcat>");
return sbXML.toString();
}
/*********************************************
* getter /setter
*********************************************/
/*********************************************
* comp_id
*********************************************/
public app.hb.ArtCatPK getComp_id()
{return this.comp_id;}
/*********************************************
* comp_id
*********************************************/
public void setComp_id(app.hb.ArtCatPK comp_id)
{ this.comp_id = comp_id;}
/*********************************************/
public app.hb.Article getarticle_art_id()
{return this.article_art_id;
}
/*********************************************/
public void setarticle_art_id(app.hb.Article article_art_id)
{ this.article_art_id =article_art_id;}
/*********************************************/
public app.hb.Categorie getcategorie_cat_id()
{return this.categorie_cat_id;
}
/*********************************************/
public void setcategorie_cat_id(app.hb.Categorie categorie_cat_id)
{ this.categorie_cat_id =categorie_cat_id;}
// Implementation de la methode toString()
public String toString() {
return new ToStringBuilder(this)
.append("comp_id", getComp_id())
.toString();
}
public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( (other== null ) ) return false;
if ( !(other instanceof ArtCat) ) return false;
ArtCat castOther = (ArtCat) other;
return new EqualsBuilder()
.append(this.getComp_id(), castOther.getComp_id())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(getComp_id())
.toHashCode();
}
}
//**********************************************
//***The test.java***
//**********************************************
// ********************* INSERT ARTICLE *********************************
id= new Integer(-1);
// Nouveau avec fichier de conf Hibernate
hsession = HibernateUtil.currentSession( );
tx = hsession.beginTransaction();
app.hb.Article llart = new app.hb.Article();
//lart.setArtId(new Integer (-1));
llart.setart_id(null);
llart.setart_code("art_code");
llart.setart_lib1("art_lib1");
llart.setart_ht(new java.math.BigDecimal(0.00));
llart.setart_ttc(new java. math.BigDecimal(0.00));
Categorie llcat = new app.hb.Categorie();
llcat= (Categorie) hsession.load(Categorie.class,new Integer(1));
tx.commit();
hsession.close();
HibernateUtil.closeSession();
//****************************************
// Nouveau avec fichier de conf Hibernate
hsession = HibernateUtil.currentSession( );
tx = hsession.beginTransaction();
ArtCatPK llArtCatPK= new ArtCatPK(null, new Integer (1));
ArtCat llArtCat= new ArtCat( llArtCatPK, llart , llcat);
Set hhs = new HashSet();
hhs.add(llArtCat);
llart.setart_cat_art_ids(hhs);
id= (Integer) hsession.save(llart);
System.out.println("insert Article ID: "+id+");");
tx.commit();
hsession.close();
HibernateUtil.closeSession();
Thank's
|