-->
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.  [ 10 posts ] 
Author Message
 Post subject: I saved an object but I can't see the changes in the db
PostPosted: Thu Jun 17, 2004 10:13 am 
Beginner
Beginner

Joined: Thu Jun 17, 2004 10:08 am
Posts: 21
Location: Paris-France
Hi,
I have the problem: i'm creating an simple object
and when i call save i cans see on the log
the insert request but when i look on the
DB there is no rows inserted !

My object is a very simple object, he got no associations at all.
I'm using Hibernate 2.1 and Oracle9i

Here are the files:


ProductAttribut.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>

<!--
Created by Middlegen Hibernate plugin

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class
name="com.influe.asp.product.hibernate.ProductAttribut"
table="PRODUCT_ATTRIBUTES"
>
<composite-id name="comp_id" class="com.influe.asp.product.hibernate.ProductAttributPK">
<key-property name="FIELD" column="FIELD" type="java.lang.String"/>
<key-property name="LN" column="LN" type="java.lang.String"/>
<key-property name="NC_LN_COD_TYP" column="NC_LN_COD_TYP" type="java.lang.String"/>
<key-property name="PN" column="PN" type="java.lang.String"/>
<key-property name="NC_PN_COD_TYP" column="NC_PN_COD_TYP" type="java.lang.String"/>
<key-property name="PV" column="PV" type="java.lang.String"/>
</composite-id>
<property
name="DT_UPDATE"
type="java.sql.Timestamp"
column="DT_UPDATE"
not-null="true"
length="7"
/>
<property
name="VALUE_S"
type="java.lang.String"
column="VALUE_S"
length="105"
/>
<property
name="VALUE_I"
type="java.lang.Long"
column="VALUE_I"
length="10"
/>
<property
name="VALUE_F"
type="java.math.BigDecimal"
column="VALUE_F"
length="20"
/>
<property
name="VALUE_DT"
type="java.sql.Timestamp"
column="VALUE_DT"
length="7"
/>
<property
name="VALUE_NC"
type="java.lang.String"
column="VALUE_NC"
length="35"
/>



</class>
</hibernate-mapping>


Here is the ProductAttributPK class

package com.influe.asp.product.hibernate;

import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;


/** @author Hibernate CodeGenerator */
public class ProductAttributPK implements Serializable {

/** identifier field */
private String FIELD;

/** identifier field */
private String LN;

/** identifier field */
private String NC_LN_COD_TYP;

/** identifier field */
private String PN;

/** identifier field */
private String NC_PN_COD_TYP;

/** identifier field */
private String PV;

/** full constructor */
public ProductAttributPK(String FIELD, String LN, String NC_LN_COD_TYP, String PN, String NC_PN_COD_TYP, String PV) {
this.FIELD = FIELD;
this.LN = LN;
this.NC_LN_COD_TYP = NC_LN_COD_TYP;
this.PN = PN;
this.NC_PN_COD_TYP = NC_PN_COD_TYP;
this.PV = PV;
}

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

public String getFIELD() {
return this.FIELD;
}

public void setFIELD(String FIELD) {
this.FIELD = FIELD;
}

public String getLN() {
return this.LN;
}

public void setLN(String LN) {
this.LN = LN;
}

public String getNC_LN_COD_TYP() {
return this.NC_LN_COD_TYP;
}

public void setNC_LN_COD_TYP(String NC_LN_COD_TYP) {
this.NC_LN_COD_TYP = NC_LN_COD_TYP;
}

public String getPN() {
return this.PN;
}

public void setPN(String PN) {
this.PN = PN;
}

public String getNC_PN_COD_TYP() {
return this.NC_PN_COD_TYP;
}

public void setNC_PN_COD_TYP(String NC_PN_COD_TYP) {
this.NC_PN_COD_TYP = NC_PN_COD_TYP;
}

public String getPV() {
return this.PV;
}

public void setPV(String PV) {
this.PV = PV;
}

public String toString() {
return new ToStringBuilder(this)
.append("FIELD", getFIELD())
.append("LN", getLN())
.append("NC_LN_COD_TYP", getNC_LN_COD_TYP())
.append("PN", getPN())
.append("NC_PN_COD_TYP", getNC_PN_COD_TYP())
.append("PV", getPV())
.toString();
}

public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( !(other instanceof ProductAttributPK) ) return false;
ProductAttributPK castOther = (ProductAttributPK) other;
return new EqualsBuilder()
.append(this.getFIELD(), castOther.getFIELD())
.append(this.getLN(), castOther.getLN())
.append(this.getNC_LN_COD_TYP(), castOther.getNC_LN_COD_TYP())
.append(this.getPN(), castOther.getPN())
.append(this.getNC_PN_COD_TYP(), castOther.getNC_PN_COD_TYP())
.append(this.getPV(), castOther.getPV())
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(getFIELD())
.append(getLN())
.append(getNC_LN_COD_TYP())
.append(getPN())
.append(getNC_PN_COD_TYP())
.append(getPV())
.toHashCode();
}

}

Here is the ProductAttribut class

package com.influe.asp.product.hibernate;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import java.lang.Long;

/** @author Hibernate CodeGenerator */
public class ProductAttribut implements Serializable {

/** identifier field */
private com.influe.asp.product.hibernate.ProductAttributPK comp_id;

/** persistent field */
private Date DT_UPDATE;

/** nullable persistent field */
private String VALUE_S;

/** nullable persistent field */
private Long VALUE_I;

/** nullable persistent field */
private BigDecimal VALUE_F;

/** nullable persistent field */
private Date VALUE_DT;

/** nullable persistent field */
private String VALUE_NC;

/** full constructor */
public ProductAttribut(com.influe.asp.product.hibernate.ProductAttributPK comp_id, Date DT_UPDATE, String VALUE_S, Long VALUE_I, BigDecimal VALUE_F, Date VALUE_DT, String VALUE_NC) {
this.comp_id = comp_id;
this.DT_UPDATE = DT_UPDATE;
this.VALUE_S = VALUE_S;
this.VALUE_I = VALUE_I;
this.VALUE_F = VALUE_F;
this.VALUE_DT = VALUE_DT;
this.VALUE_NC = VALUE_NC;
}

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

/** minimal constructor */
public ProductAttribut(com.influe.asp.product.hibernate.ProductAttributPK comp_id, Date DT_UPDATE) {
this.comp_id = comp_id;
this.DT_UPDATE = DT_UPDATE;
}

public com.influe.asp.product.hibernate.ProductAttributPK getComp_id() {
return this.comp_id;
}

public void setComp_id(com.influe.asp.product.hibernate.ProductAttributPK comp_id) {
this.comp_id = comp_id;
}

public Date getDT_UPDATE() {
return this.DT_UPDATE;
}

public void setDT_UPDATE(Date DT_UPDATE) {
this.DT_UPDATE = DT_UPDATE;
}

public String getVALUE_S() {
return this.VALUE_S;
}

public void setVALUE_S(String VALUE_S) {
this.VALUE_S = VALUE_S;
}

public Long getVALUE_I() {
return this.VALUE_I;
}

public void setVALUE_I(Long VALUE_I) {
this.VALUE_I = VALUE_I;
}

public BigDecimal getVALUE_F() {
return this.VALUE_F;
}

public void setVALUE_F(BigDecimal VALUE_F) {
this.VALUE_F = VALUE_F;
}

public Date getVALUE_DT() {
return this.VALUE_DT;
}

public void setVALUE_DT(Date VALUE_DT) {
this.VALUE_DT = VALUE_DT;
}

public String getVALUE_NC() {
return this.VALUE_NC;
}

public void setVALUE_NC(String VALUE_NC) {
this.VALUE_NC = VALUE_NC;
}

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 instanceof ProductAttribut) ) return false;
ProductAttribut castOther = (ProductAttribut) other;
return new EqualsBuilder()
.append(this.getComp_id(), castOther.getComp_id())
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(getComp_id())
.toHashCode();
}

}

Here is the conf file:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<session-factory>

<!-- properties -->
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>

<property name="connection.url">jdbc:oracle:thin:@192.168.201.53:1521:B4ONE</property>

<property name="connection.username">CDSGL</property>
<property name="connection.password">CDSGL</property>

<property name="dialect">net.sf.hibernate.dialect.Oracle9Dialect</property>

<property name="connection.pool_size">10</property>
<property name="show_sql">true</property>


<!-- mapping files -->

<mapping resource="ProductAttribut.hbm.xml"/>

</session-factory>

</hibernate-configuration>


Here is the client code :


public class MainAttribute {

public static void main(String[] args) {

try {
Configuration config = new Configuration();
config.configure(
new File("E:/eclipse2.1.3Bis/eclipse/workspace/prodHibe/xml/hibernate.cfg.xml"));

SessionFactory sessionFactory = config.buildSessionFactory();
Session session = sessionFactory.openSession();

ProductAttributPK pak =
new ProductAttributPK(
"MON_ATTR2",
"3010232918308",
"GTIN",
"0",
"GTIN",
"00");

ProductAttribut pa = new ProductAttribut(pak, new Date());

pa.setVALUE_S(" valeur att");

session.save(pa);
session.flush();
session.connection().commit();

pa =
(ProductAttribut) session.load(
com.influe.asp.product.hibernate.ProductAttribut.class,
new ProductAttributPK(
"MON_ATTR2",
"3010232918308",
"GTIN",
"0",
"GTIN",
"00"));

System.out.println(" ############ " + pa);
} catch (HibernateException hibEx) {

System.out.println(
" HibernateException - " + hibEx.getMessage());

} catch (Exception sqlEx) {
System.out.println(
" Exception - " + sqlEx.getLocalizedMessage());
}

}


And here is the loging output:

16:03:54,015 INFO Environment:462 - Hibernate 2.1.2
16:03:54,031 INFO Environment:491 - hibernate.properties not found
16:03:54,031 INFO Environment:519 - using CGLIB reflection optimizer
16:03:54,046 INFO Configuration:888 - configuring from file: hibernate.cfg.xml
16:03:54,968 INFO Configuration:311 - Mapping resource: ProductAttribut.hbm.xml
16:03:55,312 INFO Binder:229 - Mapping class: com.influe.asp.product.hibernate.ProductAttribut -> PRODUCT_ATTRIBUTES
16:03:55,671 INFO Configuration:1017 - Configured SessionFactory: null
16:03:55,671 INFO Configuration:595 - processing one-to-many association mappings
16:03:55,671 INFO Configuration:604 - processing one-to-one association property references
16:03:55,687 INFO Configuration:629 - processing foreign key constraints
16:03:55,718 INFO Dialect:82 - Using dialect: net.sf.hibernate.dialect.Oracle9Dialect
16:03:55,718 INFO SettingsFactory:62 - Use outer join fetching: true
16:03:55,734 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
16:03:55,734 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 10
16:03:55,796 INFO DriverManagerConnectionProvider:71 - using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@192.168.201.53:1521:B4ONE
16:03:55,796 INFO DriverManagerConnectionProvider:72 - connection properties: {user=CDSGL, password=CDSGL}
16:03:55,796 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
16:03:56,406 INFO SettingsFactory:102 - Use scrollable result sets: true
16:03:56,406 INFO SettingsFactory:105 - Use JDBC3 getGeneratedKeys(): false
16:03:56,406 INFO SettingsFactory:108 - Optimize cache for minimal puts: false
16:03:56,406 INFO SettingsFactory:114 - echoing all SQL to stdout
16:03:56,406 INFO SettingsFactory:117 - Query language substitutions: {}
16:03:56,406 INFO SettingsFactory:128 - cache provider: net.sf.ehcache.hibernate.Provider
16:03:56,421 INFO Configuration:1080 - instantiating and configuring caches
16:03:56,468 INFO SessionFactoryImpl:119 - building session factory
16:03:56,781 INFO SessionFactoryObjectFactory:82 - no JNDI name configured
Hibernate: insert into PRODUCT_ATTRIBUTES (DT_UPDATE, VALUE_S, VALUE_I, VALUE_F, VALUE_DT, VALUE_NC, FIELD, LN, NC_LN_COD_TYP, PN, NC_PN_COD_TYP, PV) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
16:03:56,921 DEBUG TimestampType:46 - binding '17 juin 2004 16:03:56' to parameter: 1
16:03:56,937 DEBUG StringType:46 - binding ' valeur att' to parameter: 2
16:03:56,937 DEBUG LongType:41 - binding null to parameter: 3
16:03:56,937 DEBUG BigDecimalType:41 - binding null to parameter: 4
16:03:56,937 DEBUG TimestampType:41 - binding null to parameter: 5
16:03:56,937 DEBUG StringType:41 - binding null to parameter: 6
16:03:56,937 DEBUG StringType:46 - binding 'MON_ATTR2' to parameter: 7
16:03:56,937 DEBUG StringType:46 - binding '3010232918308' to parameter: 8
16:03:56,937 DEBUG StringType:46 - binding 'GTIN' to parameter: 9
16:03:56,937 DEBUG StringType:46 - binding '0' to parameter: 10
16:03:56,937 DEBUG StringType:46 - binding 'GTIN' to parameter: 11
16:03:56,937 DEBUG StringType:46 - binding '00' to parameter: 12
############ com.influe.asp.product.hibernate.ProductAttribut@164b09c[comp_id=com.influe.asp.product.hibernate.ProductAttributPK@5eb489[FIELD=MON_ATTR2,LN=3010232918308,NC_LN_COD_TYP=GTIN,PN=0,NC_PN_COD_TYP=GTIN,PV=00]]


Thank's

Ady


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 17, 2004 11:18 am 
Beginner
Beginner

Joined: Mon Jun 07, 2004 4:21 pm
Posts: 44
Location: Boston
Are you committing the transaction?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 17, 2004 11:21 am 
Beginner
Beginner

Joined: Thu Jun 17, 2004 10:08 am
Posts: 21
Location: Paris-France
Hi,

Yes i'm doing a commit :

session.save(pa);
session.flush();
session.connection().commit();

But I don't see the raw in the DataBase and i don't understand where is the problem :((

Ady


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 17, 2004 11:25 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
begin a transaction,
don't flush( unecessary)
save object
commit and close session


there is no reason why this isn't working...

think about transaction, always!

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 17, 2004 11:37 am 
Beginner
Beginner

Joined: Thu Jun 17, 2004 10:08 am
Posts: 21
Location: Paris-France
Hi,

Thank's for your reply,
I used the transaction like you said but it still doens't working;
Why am i so stupid? I know that it should work but it doens't ....

Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();

ProductAttributPK pak =
new ProductAttributPK(
"MON_ATTR2",
"3010232918308",
"GTIN",
"0",
"GTIN",
"00");

ProductAttribut pa = new ProductAttribut(pak, new Date());

pa.setVALUE_S(" valeur att");

session.save(pa);


tx.commit();
session.close();


Here i post the log also:

17:35:35,781 INFO SessionFactoryImpl:119 - building session factory
17:35:36,375 INFO SessionFactoryObjectFactory:82 - no JNDI name configured
Hibernate: insert into PRODUCT_ATTRIBUTES (DT_UPDATE, VALUE_S, VALUE_I, VALUE_F, VALUE_DT, VALUE_NC, FIELD, LN, NC_LN_COD_TYP, PN, NC_PN_COD_TYP, PV) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
17:35:36,625 DEBUG TimestampType:46 - binding '17 juin 2004 17:35:36' to parameter: 1
17:35:36,625 DEBUG StringType:46 - binding ' valeur att' to parameter: 2
17:35:36,625 DEBUG LongType:41 - binding null to parameter: 3
17:35:36,625 DEBUG BigDecimalType:41 - binding null to parameter: 4
17:35:36,625 DEBUG TimestampType:41 - binding null to parameter: 5
17:35:36,625 DEBUG StringType:41 - binding null to parameter: 6
17:35:36,640 DEBUG StringType:46 - binding 'MON_ATTR2' to parameter: 7
17:35:36,640 DEBUG StringType:46 - binding '3010232918308' to parameter: 8
17:35:36,640 DEBUG StringType:46 - binding 'GTIN' to parameter: 9
17:35:36,640 DEBUG StringType:46 - binding '0' to parameter: 10
17:35:36,640 DEBUG StringType:46 - binding 'GTIN' to parameter: 11
17:35:36,640 DEBUG StringType:46 - binding '00' to parameter: 12


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 17, 2004 11:58 am 
Beginner
Beginner

Joined: Mon Jun 07, 2004 4:21 pm
Posts: 44
Location: Boston
Does your class implement Serializable - since it has composite-ids ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 17, 2004 11:58 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
are you sure ou are hitting the same bd?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 17, 2004 12:07 pm 
Beginner
Beginner

Joined: Thu Jun 17, 2004 10:08 am
Posts: 21
Location: Paris-France
Hi again

Yes my class is implementing Serializable interface;
Yes i'm sure that i'm hitting the same base because i have another
object that i add in the base and that one i can seet it.
As i sayed i can't see whre is the problem.
Merci beacoup Antony pour tes reponses ;)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 17, 2004 12:13 pm 
Beginner
Beginner

Joined: Mon Jun 07, 2004 4:21 pm
Posts: 44
Location: Boston
One thing to try is do the insert with JDBC - with the generated sql from Hibernate as seen in the log.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 17, 2004 12:31 pm 
Beginner
Beginner

Joined: Thu Jun 17, 2004 10:08 am
Posts: 21
Location: Paris-France
Hi,
I found the error; it was a error on a trigger in the db but i don't understant why i didn't recuperate un sqlEsception from the program; Anyway, now it's working; Thank's a lot
Have a good evening!

Ady


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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.