-->
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: not-null property references a null or transient value
PostPosted: Thu Oct 14, 2010 3:07 pm 
Newbie

Joined: Sat Aug 28, 2010 2:10 pm
Posts: 6
Hello,

I'm getting the error in the subject and I can't see any reason why I'm getting it. I'm using the following...

hibernate 3.5.7-SNAPSHOT (also occurs with 3.5.6-Final)
hibernate-jpa-2.0-api

... I have two associated classes....

Customer.java
Code:
    /** persistent field */
    @OneToMany(mappedBy="customer", targetEntity=com.inftropy.plus.account.Customer.model.Address.class, cascade = { CascadeType.ALL}, fetch=FetchType.EAGER)
    @IndexedEmbedded
    @MapKey(name="id")
    private Map<java.lang.Long, Address> addresses;


Address.java
Code:
    /** persistent field */
    @ManyToOne(targetEntity=com.inftropy.plus.account.Customer.model.Customer.class)
    @JoinColumn(name="CUSTOMER_ID")
    private com.inftropy.plus.account.Customer.model.Customer customer;


... and a simple function that adds a new customer with addresses...

Code:
  public void addCustomer(Customer customer){
    try {
      java.util.Map newAddresses=customer.getAddresses();
      customer.setAddresses(new HashMap<Long, Address>());
      java.util.Set newRoles=customer.getRoles();
      customer.setRoles(new HashSet<Role>());
      entityManager.persist(customer);
      Set newAddressesSet=newAddresses.entrySet();
      for (java.util.Iterator it = newAddressesSet.iterator(); it.hasNext();) {
        Address address=(Address)((Map.Entry)it.next()).getValue();
        address.setLastUpdated(new java.util.Date());
        address.setCustomer(customer);
        entityManager.persist(address);
        customer.getAddresses().put(address.getId(), address);
      }
      for (java.util.Iterator it = newRoles.iterator(); it.hasNext();) {
        String userRoleName=(String)it.next();
        Role possibleNewRole=getOrCreateRole(userRoleName);
        customer.getRoles().add(possibleNewRole);
      }
      entityManager.merge(customer);
    } catch(Exception e) {
      java.lang.StackTraceElement[] ste=e.getStackTrace();
      for (int cnt = 0; cnt < ste.length; cnt++)
    }
  }



... no errors occur in this function and the Customer is created fine, but later in the logic a function gets a list of roles and I get this error...

    org.hibernate.PropertyValueException: not-null property references a null or transient value: com.inftropy.plus.account.Customer.model.Address.addressLine1
    at org.hibernate.engine.Nullability.checkNullability(Nullability.java:101)
    at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:313)
    at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
    at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
    at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:69)
    at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:179)
    at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:135)
    at org.hibernate.impl.SessionImpl.firePersistOnFlush(SessionImpl.java:828)
    at org.hibernate.impl.SessionImpl.persistOnFlush(SessionImpl.java:820)
    at org.hibernate.engine.CascadingAction$9.cascade(CascadingAction.java:357)
    at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:392)
    at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:335)
    at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:204)
    at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:425)
    at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:362)
    at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:338)
    at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:204)
    at org.hibernate.engine.Cascade.cascade(Cascade.java:161)
    at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:154)
    at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:145)
    at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:88)
    at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:58)
    at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1177)
    at org.hibernate.impl.SessionImpl.scroll(SessionImpl.java:1342)
    at org.hibernate.impl.QueryImpl.scroll(QueryImpl.java:90)
    at org.hibernate.impl.QueryImpl.scroll(QueryImpl.java:80)
    at com.inftropy.plus.account.Customer.dao.impl.CustomerDAOImpl.getAllRoleObjects(CustomerDAOImpl.java:420)
    at com.inftropy.plus.account.Customer.dao.impl.CustomerDAOImpl.getAllRoles(CustomerDAOImpl.java:407)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    .
    .
    .

The addressLine1's that are passed do have data in them, so the root cause has escaped me so far, does anyone see anything I don't?

Thanks,
Ryan


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.