-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate is only inserting the id
PostPosted: Thu Apr 06, 2006 4:05 pm 
Newbie

Joined: Thu Apr 06, 2006 3:21 pm
Posts: 1
Hi all,

I wasn't sure if this should go in the JSR 220 forum or here, but here goes.

We're having a problem with our Hibernate app. We're using Hibernate 3.0.5 on Linux, Intel machines in development and PowerPC blades in QA/production. We're using the IBM JDK, version 5. We're mapping with annotations. All this works like a charm in development, but as soon as we go into production, Hibernate only inserts the primary key when we attempt to create an object.

Our object looks like this:

Code:
@TypeDef(name = "encrypted", typeClass = Encrypted.class)

@Entity(access = AccessType.FIELD)
@Table(name = "GFT_ORDER")
public class CardOrder implements Serializable
{
  public static final Long ORDER_STATUS_NEW = Long.valueOf(1L);
  public static final Long ORDER_STATUS_DECLINED = Long.valueOf(2L);
  public static final Long ORDER_STATUS_PAID = Long.valueOf(3L);
  public static final Long ORDER_STATUS_PROCESSED = Long.valueOf(4L);
  public static final Long ORDER_STATUS_ACTIVATED = Long.valueOf(5L);
  public static final Long ORDER_STATUS_CANCELED = Long.valueOf(6L);

  @Id(generate = GeneratorType.IDENTITY)
  @Column(name = "gft_order_id", nullable = false)
  private Long id;

  @Column(name = "purchaser_name", nullable = false)
  @Type(type = "encrypted")
  private String purchaserName;
  @Column(name = "purchaser_surname", nullable = false)
  @Type(type = "encrypted")
  private String purchaserSurname;
  @Column(name = "purchaser_email", nullable = false)
  @Type(type = "encrypted")
  private String purchaserEmail;
  @Column(name = "purchaser_referrer", nullable = false)
  private Long purchaserReferrer;
  @Column(name = "purchaser_marketing", nullable = false)
  private Long purchaserMarketing;
  @Column(name = "amount", nullable = false)
  private Long amount;
  @Column(name = "cardholder_name", nullable = false)
  @Type(type = "encrypted")
  private String cardHolderName;
  @Column(name = "cardholder_surname", nullable = false)
  @Type(type = "encrypted")
  private String cardHolderSurname;
  @Column(name = "cardholder_email", nullable = false)
  @Type(type = "encrypted")
  private String cardHolderEmail;
  @Column(name = "cardholder_phone", nullable = false)
  @Type(type = "encrypted")
  private String cardHolderPhone;
  @Column(name = "cardholder_marketing", nullable = false)
  private Long cardHolderMarketing;
  @Column(name = "card_name", nullable = false)
  @Type(type = "encrypted")
  private String cardName;
  @Column(name = "card_name2", nullable = false)
  private String cardName2;
  @Column(name = "mailer_text", nullable = false)
  private String mailerText;
  @Column(name = "send_email", nullable = false)
  private Long sendEmail;
  @Column(name = "post_code", nullable = false)
  private String postCode;
  @Column(name = "house_number", nullable = false)
  private String houseNumber;
  @Column(name = "house_name", nullable = false)
  private String houseName;
  @Column(name = "flat_number", nullable = false)
  private String flatNumber;
  @Column(name = "street", nullable = false)
  @Type(type = "encrypted")
  private String street;
  @Column(name = "district", nullable = false)
  private String district;
  @Column(name = "city", nullable = false)
  private String city;
  @Column(name = "county", nullable = false)
  private String county;
  @Column(name = "delivery_date", nullable = false)
  private Date deliveryDate;
  @Column(name = "use_sms", nullable = false)
  private Long useSms;
  @Column(name = "security_word", nullable = false)
  @Type(type = "encrypted")
  private String securityWord;
  @Column(name = "gft_order_status_id", nullable = false)
  private Long orderStatus;
  @Column(name = "created_on", nullable = false)
  private Date createdOn;
  @Column(name = "updated_on", nullable = false)
  private Date updatedOn;
  @Column(name = "cea_account_id", nullable = false)
  private Long accountId;

  public CardOrder()
  {
    // Initialise the non-nullable fields

    purchaserName = "";
    purchaserSurname = "";
    purchaserEmail = "";
    purchaserReferrer = Long.valueOf(0L);
    purchaserMarketing = Long.valueOf(0L);
    amount = Long.valueOf(0L);
    cardHolderName = "";
    cardHolderSurname = "";
    cardHolderEmail = "";
    cardHolderPhone = "";
    cardHolderMarketing = Long.valueOf(0L);
    cardName = "";
    cardName2 = "";
    mailerText = "";
    sendEmail = Long.valueOf(0L);
    postCode = "";
    houseNumber = "";
    houseName = "";
    flatNumber = "";
    street = "";
    district = "";
    city = "";
    county = "";
    useSms = Long.valueOf(0L);
    securityWord = "";
    orderStatus = ORDER_STATUS_NEW;
    accountId = Long.valueOf(0L);
  }

<!-- snip normal getters and setters -->
}


Code between sessionFactory.openSession() and session.close(): (edited for clarity)

Code:
      log.info("Beginning JTA transaction");
      transaction.begin();

          SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
          CardOrderDAO cardOrderDAO = new CardOrderDAOHibernate(sessionFactory.getCurrentSession());

          StringBuffer buf = new StringBuffer();
          buf.append("\nAbout to persist object with id: " + cardOrder.getId());
          buf.append("\npurchaserName: " + cardOrder.getPurchaserName());
          buf.append("\npurchaserSurname: " + cardOrder.getPurchaserSurname());
          buf.append("\npurchaserEmail: " + cardOrder.getPurchaserEmail());
          buf.append("\npurchaserReferrer: " + cardOrder.getPurchaserReferrer());
          buf.append("\npurchaserMarketing: " + cardOrder.getPurchaserMarketing());
          buf.append("\namount: " + cardOrder.getAmount());
          buf.append("\ncardHolderName: " + cardOrder.getCardHolderName());
          buf.append("\ncardHolderSurname: " + cardOrder.getCardHolderSurname());
          buf.append("\ncardHolderEmail: " + cardOrder.getCardHolderEmail());
          buf.append("\ncardHolderPhone: " + cardOrder.getCardHolderPhone());
          buf.append("\ncardHolderMarketing: " + cardOrder.getCardHolderMarketing());

          log.info("About to persist:" + buf.toString());

          cardOrderDAO.makePersistent(cardOrder);

      log.info("Committing JTA transaction");
      transaction.commit();


CardOrderDAO is standard:

Code:
  public T makePersistent(T entity)
  {
    log.debug("makePersistent for " + persistentClass.getName());

    getSession().saveOrUpdate(entity);

    return entity;
  }


We're using DB2 8.2 FP 10.

The logs look like this:

Code:
2006-04-06 15:17:38.000919 INFO  [UnitOfWork:invoke()] (Thread-7) Beginning JTA transaction
2006-04-06 15:17:38.000929 DEBUG [JDBCContext:registerSynchronizationIfPossible()] (Thread-7) successfully registered Synchronization
2006-04-06 15:17:38.000939 DEBUG [SessionImpl:<init>()] (Thread-7) opened session at timestamp: 11443510589
2006-04-06 15:17:38.000949 INFO  [GftOrderService:process()] (Thread-7) About to persist:
About to persist object with id: null
purchaserName: Colin
purchaserSurname: Colin
purchaserEmail: colin@xxx.com
purchaserReferrer: 1
purchaserMarketing: 1
amount: 5250
cardHolderName: Pablo
cardHolderSurname: Molina
cardHolderEmail: lapenya@gmail.com
cardHolderPhone:
cardHolderMarketing: 0
2006-04-06 15:17:38.000960 DEBUG [HibernateDAO:makePersistent()] (Thread-7) makePersistent for com.mycompany.gft.application.model.CardOrder
2006-04-06 15:17:38.000971 DEBUG [AbstractSaveEventListener:getEntityState()] (Thread-7) transient instance of: com.mycompany.gft.application.model.CardOrder
2006-04-06 15:17:38.000982 DEBUG [DefaultSaveOrUpdateEventListener:entityIsTransient()] (Thread-7) saving transient instance
2006-04-06 15:17:38.000993 DEBUG [AbstractSaveEventListener:performSave()] (Thread-7) saving [com.mycompany.gft.application.model.CardOrder#<null>]
2006-04-06 15:17:39.000005 DEBUG [AbstractSaveEventListener:performSaveOrReplicate()] (Thread-7) executing insertions
2006-04-06 15:17:39.000016 DEBUG [BasicEntityPersister:insert()] (Thread-7) Inserting entity: com.mycompany.gft.application.model.CardOrder (native id)
2006-04-06 15:17:39.000027 DEBUG [AbstractBatcher:logOpenPreparedStatement()] (Thread-7) about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2006-04-06 15:17:39.000038 DEBUG [ConnectionManager:openConnection()] (Thread-7) opening JDBC connection
2006-04-06 15:17:39.000051 DEBUG [SQL:log()] (Thread-7) [b]insert into GFT_ORDER (gft_order_id) values (default)[/b]
2006-04-06 15:17:39.000062 INFO  [STDOUT:write()] (Thread-7) Hibernate: insert into GFT_ORDER (gft_order_id) values (default)
2006-04-06 15:17:39.000078 DEBUG [AbstractBatcher:getPreparedStatement()] (Thread-7) preparing statement
2006-04-06 15:17:39.000089 DEBUG [BasicEntityPersister:dehydrate()] (Thread-7) Dehydrating entity: [com.mycompany.gft.application.model.CardOrder#<null>]
2006-04-06 15:17:39.000101 DEBUG [AbstractBatcher:logClosePreparedStatement()] (Thread-7) about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2006-04-06 15:17:39.000112 DEBUG [AbstractBatcher:closePreparedStatement()] (Thread-7) closing statement
2006-04-06 15:17:39.000123 DEBUG [ConnectionManager:aggressiveRelease()] (Thread-7) aggressively releasing JDBC connection
2006-04-06 15:17:39.000135 DEBUG [ConnectionManager:closeConnection()] (Thread-7) closing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2006-04-06 15:17:39.000146 DEBUG [AbstractBatcher:logOpenPreparedStatement()] (Thread-7) about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2006-04-06 15:17:39.000161 DEBUG [ConnectionManager:openConnection()] (Thread-7) opening JDBC connection
2006-04-06 15:17:39.000172 DEBUG [SQL:log()] (Thread-7) values identity_val_local()
2006-04-06 15:17:39.000183 INFO  [STDOUT:write()] (Thread-7) Hibernate: values identity_val_local()
2006-04-06 15:17:39.000201 DEBUG [AbstractBatcher:getPreparedStatement()] (Thread-7) preparing statement
2006-04-06 15:17:39.000213 DEBUG [IdentifierGeneratorFactory:getGeneratedIdentity()] (Thread-7) Natively generated identity: 100002
2006-04-06 15:17:39.000225 DEBUG [AbstractBatcher:logClosePreparedStatement()] (Thread-7) about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2006-04-06 15:17:39.000236 DEBUG [AbstractBatcher:closePreparedStatement()] (Thread-7) closing statement
2006-04-06 15:17:39.000248 DEBUG [ConnectionManager:aggressiveRelease()] (Thread-7) aggressively releasing JDBC connection
2006-04-06 15:17:39.000259 DEBUG [ConnectionManager:closeConnection()] (Thread-7) closing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2006-04-06 15:17:39.000270 INFO  [UnitOfWork:invoke()] (Thread-7) Committing JTA transaction
2006-04-06 15:17:39.000280 DEBUG [CacheSynchronization:beforeCompletion()] (Thread-7) transaction before completion callback
2006-04-06 15:17:39.000295 DEBUG [CacheSynchronization:beforeCompletion()] (Thread-7) automatically flushing session
2006-04-06 15:17:39.000310 DEBUG [SessionImpl:managedFlush()] (Thread-7) automatically flushing session
2006-04-06 15:17:39.000326 DEBUG [AbstractFlushingEventListener:flushEverythingToExecutions()] (Thread-7) flushing session
2006-04-06 15:17:39.000341 DEBUG [AbstractFlushingEventListener:prepareEntityFlushes()] (Thread-7) processing flush-time cascades
2006-04-06 15:17:39.000356 DEBUG [AbstractFlushingEventListener:prepareCollectionFlushes()] (Thread-7) dirty checking collections
2006-04-06 15:17:39.000371 DEBUG [AbstractFlushingEventListener:flushEntities()] (Thread-7) Flushing entities and processing referenced collections
2006-04-06 15:17:39.000387 DEBUG [AbstractFlushingEventListener:flushCollections()] (Thread-7) Processing unreferenced collections
2006-04-06 15:17:39.000402 DEBUG [AbstractFlushingEventListener:flushCollections()] (Thread-7) Scheduling collection removes/(re)creates/updates
2006-04-06 15:17:39.000418 DEBUG [AbstractFlushingEventListener:flushEverythingToExecutions()] (Thread-7) Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
2006-04-06 15:17:39.000433 DEBUG [AbstractFlushingEventListener:flushEverythingToExecutions()] (Thread-7) Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2006-04-06 15:17:39.000448 DEBUG [Printer:toString()] (Thread-7) [b]listing entities:[/b]
2006-04-06 15:17:39.000464 DEBUG [Printer:toString()] (Thread-7) [b]com.mycompany.gft.application.model.CardOrder{mailerText=ryyutyutyu, cardHolderEmail=lapenya@gmail.com, cardName=El Pableras, cardHolderMarketing=0, id=100002, orderStatus=1, deliveryDate=2006-04-20 00:00:00, houseName=, updatedOn=2006-04-06 15:17:38, houseNumber=80, city=London, cardHolderSurname=Molina, cardName2=Congratulations, district=London, street=Falcon Lane, useSms=0, cardHolderPhone=, purchaserMarketing=1, county=London, amount=5250, accountId=0, cardHolderName=Pablo, purchaserReferrer=1, securityWord=, purchaserName=Colin, postCode=SW11 2LJ, purchaserEmail=colin@xxxx.com, createdOn=2006-04-06 15:17:38, purchaserSurname=Colin, sendEmail=1, flatNumber=9A}[/b]
2006-04-06 15:17:39.000479 DEBUG [AbstractFlushingEventListener:performExecutions()] (Thread-7) executing flush
2006-04-06 15:17:39.000495 DEBUG [AbstractFlushingEventListener:postFlush()] (Thread-7) post flush
2006-04-06 15:17:39.000510 DEBUG [JDBCContext:beforeTransactionCompletion()] (Thread-7) before transaction completion
2006-04-06 15:17:39.000525 DEBUG [SessionImpl:beforeTransactionCompletion()] (Thread-7) before transaction completion
2006-04-06 15:17:39.000542 DEBUG [CacheSynchronization:afterCompletion()] (Thread-7) transaction after completion callback, status: 3
2006-04-06 15:17:39.000556 DEBUG [JDBCContext:afterTransactionCompletion()] (Thread-7) after transaction completion
2006-04-06 15:17:39.000571 DEBUG [SessionImpl:afterTransactionCompletion()] (Thread-7) after transaction completion
2006-04-06 15:17:39.000585 DEBUG [CacheSynchronization:afterCompletion()] (Thread-7) automatically closing session
2006-04-06 15:17:39.000600 DEBUG [SessionImpl:managedClose()] (Thread-7) automatically closing session
2006-04-06 15:17:39.000615 DEBUG [SessionImpl:close()] (Thread-7) closing session


Is there anything obvious we're doing wrong?

Thanks in advance for any and all help.


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

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.