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: making composite key from onetoone mapping
PostPosted: Tue May 01, 2012 3:57 am 

Joined: Tue May 01, 2012 3:48 am
Posts: 1
Hello developers,

I am making an attempt to make a composite id from a onetoone mapping but it gives me an error.
Can anyone help me with this problem.

This are my codes:
@Table(name = "pos_salescashpayment")
@AssociationOverride(name = "cashSalePaymentPk.cashSaleTx", joinColumns =
@JoinColumn(name = "cTransNo"))
public class CashSalePayment implements Serializable {

    private CashSalePaymentPk cashSalePaymentPk;
    private PaymentType paymentType;
    private int refNo;
    private double amount;

    public CashSalePaymentPk getCashSalePaymentPk() {
        return cashSalePaymentPk;

    public void setCashSalePaymentPk(CashSalePaymentPk cashSalePaymentPk) {
        this.cashSalePaymentPk = cashSalePaymentPk;

    public CashSaleTx getCashSaleTx() {
        return getCashSalePaymentPk().getCashSaleTx();

    public void setCashSaleTx(CashSaleTx cashSaleTx) {

    @Column(name = "nAmount")
    public double getAmount() {
        return amount;

    public void setAmount(double amount) {
        this.amount = amount;

    @JoinColumn(name = "cPayType")
    public PaymentType getPaymentType() {
        return paymentType;

    public void setPaymentType(PaymentType paymentType) {
        this.paymentType = paymentType;

    @Column(name = "cRefNo")
    public int getRefNo() {
        return refNo;

    public void setRefNo(int refNo) {
        this.refNo = refNo;

public class CashSalePaymentPk implements Serializable {

    private CashSaleTx cashSaleTx;

    @OneToOne(targetEntity=CashSaleTx.class,fetch= FetchType.LAZY)
    public CashSaleTx getCashSaleTx() {
        return cashSaleTx;

    public void setCashSaleTx(CashSaleTx cashSaleTx) {
        this.cashSaleTx = cashSaleTx;

public synchronized CashSalePayment getCashSalePaymentByTransNo(String transNo) {
        Session session = PointOfSaleUtil.getSessionFactory().openSession();
        CashSalePayment cashSalePayment = null;
        Criteria criteria = session.createCriteria(CashSalePayment.class)
                .add(Restrictions.eq("cashSalePaymentPk.cashSaleTx.txNo", transNo));
        cashSalePayment = (CashSalePayment) criteria.uniqueResult();
        return cashSalePayment;

and this are the errors :

May 01, 2012 3:46:59 PM org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity com.vg.vmi.dealer.pos.ent.CashSalePayment on table pos_salescashpayment
Initial SessionFactory creation failed.org.hibernate.AnnotationException: Illegal attempt to define a @JoinColumn with a mappedBy association: cashSalePaymentPk.cashSaleTx
Exception in thread "main" java.lang.ExceptionInInitializerError
   at com.vg.vmi.dealer.pos.util.PointOfSaleUtil.<clinit>(PointOfSaleUtil.java:54)
   at com.vg.vmi.dealer.pos.entmgr.CashSalePaymentManager.getCashSalePaymentByPaymentType(CashSalePaymentManager.java:89)
   at com.vg.vmi.dealer.pos.entmgr.CashSalePaymentManager.main(CashSalePaymentManager.java:103)
Caused by: org.hibernate.AnnotationException: Illegal attempt to define a @JoinColumn with a mappedBy association: cashSalePaymentPk.cashSaleTx
   at org.hibernate.cfg.Ejb3JoinColumn.buildJoinColumn(Ejb3JoinColumn.java:152)
   at org.hibernate.cfg.Ejb3JoinColumn.buildJoinColumns(Ejb3JoinColumn.java:127)
   at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1212)
   at org.hibernate.cfg.AnnotationBinder.fillComponent(AnnotationBinder.java:1841)
   at org.hibernate.cfg.AnnotationBinder.bindId(AnnotationBinder.java:1878)
   at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1281)
   at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:754)
   at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:534)
   at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:286)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
   at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
   at com.vg.vmi.dealer.pos.util.PointOfSaleUtil.<clinit>(PointOfSaleUtil.java:36)
   ... 2 more
Java Result: 1


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.