-->
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: INSERT does not populate.
PostPosted: Mon Mar 10, 2008 10:38 am 
Newbie

Joined: Sat Mar 08, 2008 2:25 pm
Posts: 2
The problem I am having is best summed up in the generated SQL. There are two things wrong with this SQL. First, the USERID is last and should be first. Second, apparently it is not injecting data from the class variables into the SQL to be persisted. I have verified that the data exisits, you can see some of it between "GOT HERE 4" and "GOT HERE 5" and again after the flush before the SQL (If you didn't catch it in the code.)

Thank you!

Hibernate version:
3.2

Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
   <session-factory>
      <property name="connection.username">OCMTB</property>
      <property name="connection.password">mbert16</property>
      <property name="connection.url">jdbc:db2:DLFMDEV</property>
      <property name="connection.driver_class">COM.ibm.db2.jdbc.app.DB2Driver</property>
      <property name="dialect">org.hibernate.dialect.DB2Dialect</property>
      <property name="show_sql">true</property>
      <mapping resource="NewUser.hbm.xml"/>
   </session-factory>
</hibernate-configuration>


Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="test">
  <class name="NewUser" schema="DLFM" table="TUSERS">
     <id name="UserID" column="USERID" type="string" length = "8">
        <generator class="assigned"/>
     </id>
     <property name="Password" column="PASSWORD" type="string" length = "32"></property>
     <property name="LastName" column="LASTNAME" type="string" length = "24"></property>
     <property name="FirstName" column="FIRSTNAME" type="string" length = "24"></property>
     <property name="UserEmail" column="USEREMAIL" type="string" length = "64"></property>
     <property name="ForcePW" column="FORCEPASSWORD" type="boolean"></property>
     <property name="ManageTemplates" column="MANAGETEMPLATES" type="boolean"></property>
     <property name="Staging" column="STAGING" type="boolean"></property>
     <property name="Operations" column="OPERATIONS" type="boolean"></property>
     <property name="Destaging" column="DESTAGING"  type="boolean"></property>
     <property name="TapeLib" column="TAPELIB" type="boolean"></property>
     <property name="QueryView" column="QUERYVIEW" type="boolean"></property>
     <property name="Admin" column="ADMIN" type="boolean"></property>
     <property name="Created" column="DATECREATED" type="date"></property>
     <property name="LastMod" column="DATELASTMOD" type="date"></property>   
  </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

MAIN
Code:
package test;

public class TestMain {

   public static void main(String[] args) {
      InsertNewUser inu = new InsertNewUser();
      NewUser nu = new NewUser(true);
      inu.insert(nu);
   }

}

NewUser Class
Code:
package test;

import java.util.Date;

public class NewUser{
   
   //   String values
   private String UserID = null;
   private String Password = null;
   private String LastName = null;
   private String FirstName = null;
   private String UserEmail = null;

   //   boolean values
   private boolean ForcePW;
   private boolean ManageTemplates;
   private boolean Staging;
   private boolean Operations;
   private boolean Destaging;
   private boolean TapeLib;
   private boolean QueryView;
   private boolean Admin;
   
   //   Date and related values
   private Date Created;
   private Date LastMod;
   
   public NewUser(){
      ForcePW = true;      
      Created = new Date();
      LastMod = Created;
   }
   
   public NewUser(String UserID, String Password, String LastName, String FirstName,
         String UserEmail, boolean ManageTemplates, boolean Staging,
         boolean Operations, boolean Destaging, boolean TapeLib, boolean QueryView,
         boolean Admin){
      this.UserID = UserID;
      this.Password = Password;
      this.LastName = LastName;
      this.FirstName = FirstName;
      this.UserEmail = UserEmail;
      this.ForcePW = true;
      this.ManageTemplates = ManageTemplates;
      this.Staging = Staging;
      this.Operations = Operations;
      this.Destaging = Destaging;
      this.TapeLib = TapeLib;
      this.QueryView = QueryView;
      this.Admin = Admin;
      
      this.Created = new Date();
      this.LastMod = this.Created;
      
   }
   
   public NewUser(boolean b){
      if(b){
         this.UserID = "TEST";
         this.Password = "abcdefghijklmnopqrstuvwxyz123456";
         this.LastName = "McTesterson";
         this.FirstName = "Tester";
         this.UserEmail = "t.test@testy.tst";
         this.ForcePW = true;
         this.ManageTemplates = true;
         this.Staging = false;
         this.Operations = true;
         this.Destaging = true;
         this.TapeLib = false;
         this.QueryView = false;
         this.Admin = true;
         this.Created = new Date();
         this.LastMod = this.Created;
      }      
   }
   
   public void setCreated(Date d){
      this.Created = d;
   }
   
   /* (non-Javadoc)
    * @see test.User#setAdmin(boolean)
    */
   public void setAdmin(boolean b){
      this.Admin = b;
   }

   /* (non-Javadoc)
    * @seetest.User#getAdmin()
    */
   public boolean getAdmin() {
      System.out.println(this.Admin);
      return this.Admin;
   }

   /* (non-Javadoc)
    * @see client.session.admin.User#getCreated()
    */
   public Date getCreated() {
      System.out.println(this.Created);
      return this.Created;
   }

   /* (non-Javadoc)
    * @see test.User#setDestaging(boolean)
    */
   public void setDestaging(boolean b){
      this.Destaging = b;
   }
   /* (non-Javadoc)
    * @see test.User#getDestaging()
    */
   public boolean getDestaging() {
      return this.Destaging;
   }

   /* (non-Javadoc)
    * @see test.User#setFirstName(java.lang.String)
    */
   public void setFirstName(String s){
      this.FirstName = s;
   }
   /* (non-Javadoc)
    * @see test.User#getFirstName()
    */
   public String getFirstName() {
      return this.FirstName;
   }
   
   public void setForcePW(boolean b){
      this.ForcePW = b;
   }
   
   /* (non-Javadoc)
    * @see test.User#getForcePW()
    */
   public boolean getForcePW() {
      return this.ForcePW;
   }
   /* (non-Javadoc)
    * @see test.User#setLatName(java.lang.String)
    */
   public void setLastName(String s){
      this.LastName = s;
   }
   /* (non-Javadoc)
    * @see test.User#getLastName()
    */
   public String getLastName() {
      return this.LastName;
   }
   
   public Date getLastMod(){
      return  this.LastMod;
   }
   
   public void setLastMod(Date d){
      this.LastMod = d;
   }
   
   /* (non-Javadoc)
    * @see test.User#setManageTemplates(boolean)
    */
   public void setManageTemplates(boolean b){
      this.ManageTemplates = b;
   }
   /* (non-Javadoc)
    * @see test.User#getManageTemplates()
    */
   public boolean getManageTemplates() {
      return this.ManageTemplates;
   }

   /* (non-Javadoc)
    * @see test.User#setOperations(boolean)
    */
   public void setOperations(boolean b){
      this.Operations = b;
   }
   /* (non-Javadoc)
    * @see test.User#getOperations()
    */
   public boolean getOperations() {
      return this.Operations;
   }

   /* (non-Javadoc)
    * @see test.User#setPassword(java.lang.String)
    */
   public void setPassword(String s){
      //   TODO ADD password MD5 Hash.
      this.Password = s;
   }
   
   /* (non-Javadoc)
    * @see test.User#getPassword()
    */
   public String getPassword() {
      return this.Password;
   }
   /* (non-Javadoc)
    * @see test.User#setQueryView(boolean)
    */
   public void setQueryView(boolean b){
      this.QueryView = b;
   }
   
   /* (non-Javadoc)
    * @see test.User#getQueryView()
    */
   public boolean getQueryView() {
      return this.QueryView;
   }

   /* (non-Javadoc)
    * @see test.User#setStaging(boolean)
    */
   public void setStaging(boolean b){
      this.Staging = b;
   }
   
   /* (non-Javadoc)
    * @see test.User#getStageing()
    */
   public boolean getStaging() {
      return this.Staging;
   }

   /* (non-Javadoc)
    * @see test.User#setTapeLib(boolean)
    */
   public void setTapeLib(boolean b){
      this.TapeLib = b;
   }
   
   /* (non-Javadoc)
    * @see test.User#getTapeLib()
    */
   public boolean getTapeLib() {
      return this.TapeLib;
   }

   /* (non-Javadoc)
    * @see test.User#setUserID(java.lang.String)
    */
   public void setUserID(String s){
      this.UserID = s;
   }
   
   /* (non-Javadoc)
    * @see test.User#getUserID()
    */
   public String getUserID() {
      return this.UserID;
   }
   /* (non-Javadoc)
    * @see test.User#setUserEmail(java.lang.String)
    */
   public void setUserEmail(String s){
      this.UserEmail = s;
   }
   /* (non-Javadoc)
    * @see test.User#getUserEmail()
    */
   public String getUserEmail() {
      return this.UserEmail;
   }
}

InsertNewUser Class
Code:
package test;

import org.hibernate.cfg.Configuration;
import org.hibernate.SessionFactory;
import org.hibernate.Session;

public class InsertNewUser {
   Configuration cfg = null;
   SessionFactory factory = null;
   
   public InsertNewUser(){
      this.cfg = new Configuration();
      System.out.println("GOT HERE 1");
      this.factory = cfg.configure().buildSessionFactory();
      System.out.println("GOT HERE 2");
   }
   
   public void insert(NewUser nu){
      Session session = factory.openSession();
      System.out.println("GOT HERE 4");
      session.save(nu);
      System.out.println("GOT HERE 5");
      session.flush();
      System.out.println("GOT HERE 6");
      session.close();
      System.out.println("GOT HERE 7");      
   }   
}

Full stack trace of any exception that occurs:
Code:
IWAV0055I Java Bean test.TestMain started with the main method
Mar 10, 2008 9:11:05 AM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.4.sp1
Mar 10, 2008 9:11:05 AM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Mar 10, 2008 9:11:05 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
Mar 10, 2008 9:11:05 AM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
GOT HERE 1
Mar 10, 2008 9:11:05 AM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Mar 10, 2008 9:11:05 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Mar 10, 2008 9:11:05 AM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : NewUser.hbm.xml
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: test.NewUser -> TUSERS
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Mar 10, 2008 9:11:06 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Mar 10, 2008 9:11:06 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
Mar 10, 2008 9:11:06 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Mar 10, 2008 9:11:06 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: COM.ibm.db2.jdbc.app.DB2Driver at URL: jdbc:db2:DLFMDEV
Mar 10, 2008 9:11:06 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=OCMTB, password=****}
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: DB2/NT, version: 08.02.0007
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: IBM DB2 JDBC 2.0 Type 2, version: 08.02.0007
Mar 10, 2008 9:11:06 AM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.DB2Dialect
Mar 10, 2008 9:11:06 AM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
Mar 10, 2008 9:11:06 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Mar 10, 2008 9:11:06 AM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Mar 10, 2008 9:11:06 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Mar 10, 2008 9:11:06 AM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Mar 10, 2008 9:11:07 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
GOT HERE 2
GOT HERE 4
true
Mon Mar 10 09:11:07 CDT 2008
GOT HERE 5
true
Mon Mar 10 09:11:07 CDT 2008
Hibernate: insert into DLFM.TUSERS (PASSWORD, LASTNAME, FIRSTNAME, USEREMAIL, FORCEPASSWORD, MANAGETEMPLATES, STAGING, OPERATIONS, DESTAGING, TAPELIB, QUERYVIEW, ADMIN, DATECREATED, DATELASTMOD, USERID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
GOT HERE 6
GOT HERE 7


Name and version of the database you are using:
DB2 v8

The generated SQL (show_sql=true):
Code:
Hibernate: insert into DLFM.TUSERS (PASSWORD, LASTNAME, FIRSTNAME, USEREMAIL, FORCEPASSWORD, MANAGETEMPLATES, STAGING, OPERATIONS, DESTAGING, TAPELIB, QUERYVIEW, ADMIN, DATECREATED, DATELASTMOD, USERID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 11, 2008 4:37 pm 
Newbie

Joined: Sat Mar 08, 2008 2:25 pm
Posts: 2
Maybe the "?" should be there?

But still, I am having issues with the Primary Key. It is generating the SQL with the USERID column at the end and it should be FIRST. I am using "Assigned" as the generator method, as I understand it, this means that I assign the primary key and not Hibernate, which is what I want.

Any ideas what I am doing wrong that would cause it to map the first column to the last column in the SQL?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 13, 2008 12:51 pm 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
Hi,

can't see anything wrong with the sql....
1.) Column-order is irrelevant since the generated statement explicitly states the column-names, so the DBMS should know where to putr which value.
2.) The output generated by show_sql=true will not print the values bound to the JDBC-Parameters, so you just don't know what values are bound to the Parameters.

The matter of your objects not appearing in the database seems more like there is no
session.beginTransaction()
and no commit in your program....


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.