-->
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: Provided id of the wrong type for class
PostPosted: Thu Mar 10, 2016 7:39 am 
Newbie

Joined: Thu Mar 10, 2016 6:59 am
Posts: 1
I was trying to save object of Consumer.java . But while doing it, getting below exception:

Stack trace is as below:

Code:
org.hibernate.TypeMismatchException: Provided id of the wrong type for class com.citruspay.common.domain.consumer.ConsumerDetail. Expected: class java.lang.Integer, got class org.hibernate.action.internal.DelayedPostInsertIdentifier
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:134)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1106)
at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1025)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:716)
at org.hibernate.type.EntityType.resolve(EntityType.java:502)
at org.hibernate.type.EntityType.replace(EntityType.java:366)
at org.hibernate.type.AbstractType.replace(AbstractType.java:178)
at org.hibernate.type.TypeHelper.replace(TypeHelper.java:227)
at org.hibernate.event.internal.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:444)
at org.hibernate.event.internal.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:249)
at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:189)
at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:85)
at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:876)
at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:858)
at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:863)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:1196)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:344)
at com.sun.proxy.$Proxy118.merge(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:294)
at com.sun.proxy.$Proxy118.merge(Unknown Source)


Code snippet is:

Code:
@Repository
@Transactional
public class ConsumerDAOImpl implements ConsumerDAO {

   private static final Logger logger = LoggerFactory
        .getLogger(ConsumerDAOImpl.class);

   @PersistenceContext
   private EntityManager em;

   public Consumer saveOrUpdate(Consumer consumer) {
      return em.merge(consumer);
   }
}


I am getting exception when calling method em.merge(consumer).
Entity class:

Code:
@Entity
@Audited
@Table(name = "CON_CONSUMER")
public class Consumer implements Serializable {

private static final long serialVersionUID = -8211543793922969543L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;   

@Embedded   
private WalletPreference walletPreference;
@NotNull
@OneToOne   
private ConsumerDetail consumerDetail;

@Temporal(TemporalType.TIMESTAMP)
private Date created;

@Temporal(TemporalType.TIMESTAMP)
@Version
private Date lastModified;

@Enumerated(EnumType.STRING)
private ConsumerStatus consumerFlag;

@OneToOne(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
private CPUser cpUser;

@OneToMany(mappedBy="consumer" ,cascade=CascadeType.ALL)
@Where(clause="deleted <> '1'")
private List<ConsumerCustomParameter> customParameter;

public Consumer() {
}

public Consumer(String firstName, String lastName, Address contactAddress, List<PhoneNumber> phoneNumber) {
    super();   
    this.created = new Date();
}

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

public WalletPreference getWalletPreference() {
    return walletPreference;
}

public void setWalletPreference(WalletPreference walletPreference) {
    this.walletPreference = walletPreference;
}

public Date getCreated() {
    return created;
}

public void setCreated(Date created) {
    this.created = created;
}

public Date getLastModified() {
    return lastModified;
}

public void setLastModified(Date lastModified) {
    this.lastModified = lastModified;
}

public ConsumerDetail getConsumerDetail() {
    return consumerDetail;
}

public void setConsumerDetail(ConsumerDetail consumerDetail) {
    this.consumerDetail = consumerDetail;
}

public ConsumerStatus getConsumerFlag() {
    return consumerFlag;
}

public void setConsumerFlag(ConsumerStatus consumerFlag) {
    this.consumerFlag = consumerFlag;
}

public CPUser getCPUser(){
     return cpUser;
}

public void setCPUser(CPUser cpUser) {
    this.cpUser = cpUser;
}

public List<ConsumerCustomParameter> getCustomParameter() {
    return customParameter;
}

public void setCustomParameter(List<ConsumerCustomParameter> customParameter) {
    this.customParameter = customParameter;
}

@Override
public String toString() {
    return "Consumer [id=" + id + ", created=" + created
            + ", lastModified=" + lastModified + ", consumerFlag="
            + consumerFlag + ", customParameter=" + customParameter + "]";
}


Code for saving Consumer POJO:

Code:
public class ConsumerProfileServiceImpl implements ConsumerProfileService        {

    @Autowired
    private ConsumerDAO consumerDAO;

    @Transactional
    public Consumer createConsumer(CPUser cpUser, DefaultPerson person) {
        Consumer consumer = new Consumer();
        ConsumerDetail consumerDetail = //setting consumer details

        consumer.setCreated(new Date());
        consumer.setConsumerFlag(ConsumerStatus.ENABLED);

        consumer.setCPUser(); // set it to some cpuser object

        ConsumerDetail savedConsumerDetails = consumerDetailDAO
            .saveOrUpdate(consumerDetail);
        consumer.setConsumerDetail(savedConsumerDetails);

        consumer = consumerDAO.saveOrUpdate(consumer);
    }
}


I am using hibernate version 4.3.11.Final, Spring 4.2.5.RELEASE. Let me know If you need more information. Can anybody urgently help here?


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.