-->
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.  [ 2 posts ] 
Author Message
 Post subject: Newbie - many-to-one annotation question
PostPosted: Tue Feb 05, 2008 12:34 pm 
Newbie

Joined: Thu Feb 15, 2007 3:32 pm
Posts: 10
Hello,

I'm having trouble with a many-to-one relationship (see below - getNmlBatch() ). The foreign key on the many is not being recognized. So the insert statement does not contain the foreign key and I get a cannot insert null into ...

Any suggestions ??

Many side object
Code:
package com.west.nml.domain;
// Generated Jan 25, 2008 12:05:50 PM by Hibernate Tools 3.2.0.beta8


import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
* NMLNovusPayload generated by hbm2java
*/
@Entity
@Table(name="MACHV.NML_NOVUS_PAYLOAD"
)
public class NMLNovusPayload implements java.io.Serializable {

    // Fields   

     private String payloadFilename;
     private NMLBatch nmlBatch;
     private NMLAdhocRequest nmlAdhocRequest;
     private Date ltcRequestDatetime;
     private Date ltcResponseDatetime;
     private String ltcResponse;
     private String errorMessage;
     private Set<NMLNovusDocPayload> nmlNovusDocPayloads = new HashSet<NMLNovusDocPayload>(0);
//    private Set<NMLNovusCollection> nmlNovusCollections = new HashSet<NMLNovusCollection>(0);

     // Constructors

    /** default constructor */
    public NMLNovusPayload() {
    }

   /** minimal constructor */
    public NMLNovusPayload(String payloadFilename, NMLBatch nmlBatch) {
        this.payloadFilename = payloadFilename;
        this.nmlBatch = nmlBatch;
    }
    /** full constructor */
    public NMLNovusPayload(String payloadFilename, NMLBatch nmlBatch, NMLAdhocRequest nmlAdhocRequest, Date ltcRequestDatetime, Date ltcResponseDatetime, String ltcResponse, String errorMessage, Set<NMLNovusDocPayload> nmlNovusDocPayloads) {
       this.payloadFilename = payloadFilename;
       this.nmlBatch = nmlBatch;
       this.nmlAdhocRequest = nmlAdhocRequest;
       this.ltcRequestDatetime = ltcRequestDatetime;
       this.ltcResponseDatetime = ltcResponseDatetime;
       this.ltcResponse = ltcResponse;
       this.errorMessage = errorMessage;
       this.nmlNovusDocPayloads = nmlNovusDocPayloads;
    }
   
    // Property accessors
     @Id
   
    @Column(name="PAYLOAD_FILENAME", unique=false, nullable=false, insertable=true, updatable=true, length=50)
    public String getPayloadFilename() {
        return this.payloadFilename;
    }
   
    public void setPayloadFilename(String payloadFilename) {
        this.payloadFilename = payloadFilename;
    }
@ManyToOne(cascade={},  fetch=FetchType.LAZY)
@JoinColumn(name="BATCH_UUID", unique=false, nullable=false, insertable=false, updatable=false)

    public NMLBatch getNmlBatch() {
        return this.nmlBatch;
    }   
    public void setNmlBatch(NMLBatch nmlBatch) {
        this.nmlBatch = nmlBatch;
    }
@ManyToOne(cascade={},
        fetch=FetchType.LAZY)
   
    @JoinColumn(name="RESENT_ADHOC_UUID", unique=false, nullable=true, insertable=true, updatable=true)
    public NMLAdhocRequest getNmlAdhocRequest() {
        return this.nmlAdhocRequest;
    }
   
    public void setNmlAdhocRequest(NMLAdhocRequest nmlAdhocRequest) {
        this.nmlAdhocRequest = nmlAdhocRequest;
    }
   
    @Column(name="LTC_REQUEST_DATETIME", unique=false, nullable=true, insertable=true, updatable=true, length=7)
    public Date getLtcRequestDatetime() {
        return this.ltcRequestDatetime;
    }
   
    public void setLtcRequestDatetime(Date ltcRequestDatetime) {
        this.ltcRequestDatetime = ltcRequestDatetime;
    }
   
    @Column(name="LTC_RESPONSE_DATETIME", unique=false, nullable=true, insertable=true, updatable=true, length=7)
    public Date getLtcResponseDatetime() {
        return this.ltcResponseDatetime;
    }
   
    public void setLtcResponseDatetime(Date ltcResponseDatetime) {
        this.ltcResponseDatetime = ltcResponseDatetime;
    }
   
    @Column(name="LTC_RESPONSE", unique=false, nullable=true, insertable=true, updatable=true, length=100)
    public String getLtcResponse() {
        return this.ltcResponse;
    }
   
    public void setLtcResponse(String ltcResponse) {
        this.ltcResponse = ltcResponse;
    }
   
    @Column(name="ERROR_MESSAGE", unique=false, nullable=true, insertable=true, updatable=true, length=1000)
    public String getErrorMessage() {
        return this.errorMessage;
    }
   
    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }
    @OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.LAZY, mappedBy="nmlNovusPayload")
    public Set<NMLNovusDocPayload> getNmlNovusDocPayloads() {
        return this.nmlNovusDocPayloads;
    }
   
    public void setNmlNovusDocPayloads(Set<NMLNovusDocPayload> nmlNovusDocPayloads) {
        this.nmlNovusDocPayloads = nmlNovusDocPayloads;
    }


//    @ManyToMany(cascade={CascadeType.ALL},  mappedBy="nmlNovusPayloads",  targetEntity= NMLNovusCollection.class)
//    public Set<NMLNovusCollection> getNmlNovusCollections()
//    {
//        return nmlNovusCollections;
//    }
//
//    public void setNmlNovusCollections(Set<NMLNovusCollection> nmlNovusCollections)
//    {
//        this.nmlNovusCollections = nmlNovusCollections;
//    }



    public String toString()
    {
        StringBuffer sb = new StringBuffer();
        sb.append("payloadFilename: " + payloadFilename);

        if (ltcRequestDatetime != null)
        {
            sb.append("ltcRequestDateTime: " + ltcRequestDatetime.toString());
        }
        return sb.toString();
    }




}



One side object
Code:
package com.west.nml.domain;

// Generated Jan 25, 2008 12:05:50 PM by Hibernate Tools 3.2.0.beta8


import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
* NMLBatch generated by hbm2java
*/
@Entity
@Table(name = "MACHV.NML_BATCH"
)
public class NMLBatch implements java.io.Serializable
{

    // Fields   

    private String batchUuid;
    private Date requestDatetime;
    private Set<NMLNovusPayload> nmlNovusPayloads = new HashSet<NMLNovusPayload>(0);

    // Constructors

    /**
     * default constructor
     */
    public NMLBatch()
    {
    }

    /**
     * minimal constructor
     */
    public NMLBatch(String batchUuid, Date requestDatetime)
    {
        this.batchUuid = batchUuid;
        this.requestDatetime = requestDatetime;
    }

    /**
     * full constructor
     */
    public NMLBatch(String batchUuid, Date requestDatetime, Set<NMLNovusPayload> nmlNovusPayloads)
    {
        this.batchUuid = batchUuid;
        this.requestDatetime = requestDatetime;
        this.nmlNovusPayloads = nmlNovusPayloads;
    }

    // Property accessors
    @Id

    @Column(name = "BATCH_UUID", unique = false, nullable = false, insertable = true, updatable = true, length = 33)
    public String getBatchUuid()
    {
        return this.batchUuid;
    }

    public void setBatchUuid(String batchUuid)
    {
        this.batchUuid = batchUuid;
    }

    @Column(name = "REQUEST_DATETIME", unique = false, nullable = false, insertable = true, updatable = true, length = 7)
    public Date getRequestDatetime()
    {
        return this.requestDatetime;
    }

    public void setRequestDatetime(Date requestDatetime)
    {
        this.requestDatetime = requestDatetime;
    }

    @OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY, mappedBy = "nmlBatch")
    public Set<NMLNovusPayload> getNmlNovusPayloads()
    {
        return this.nmlNovusPayloads;
    }

    public void setNmlNovusPayloads(Set<NMLNovusPayload> nmlNovusPayloads)
    {
        this.nmlNovusPayloads = nmlNovusPayloads;
    }

    public String toString()
    {
        StringBuffer sb = new StringBuffer();
        sb.append("batchUuid: " + batchUuid);
        sb.append("requestDateTime: " + requestDatetime);
//        sb.append(nmlNovusPayloads.toString());

        return sb.toString();
    }

}




Test:
Code:
        NMLNovusPayload payload = new NMLNovusPayload();
        payload.setPayloadFilename("PayloadTest2");
       
        NMLBatch nmlBatch = new NMLBatch();
        nmlBatch.setBatchUuid("batchUuid2                       ");
        nmlBatch.setRequestDatetime(new Date(System.currentTimeMillis()));

        payload.setNmlBatch(nmlBatch);

        dao.saveOrUpdate(payload);




Hibernate SQL :
Code:
Hibernate:
    select
        nmlnovuspa_.PAYLOAD_FILENAME,
        nmlnovuspa_.ERROR_MESSAGE as ERROR2_3_,
        nmlnovuspa_.LTC_REQUEST_DATETIME as LTC3_3_,
        nmlnovuspa_.LTC_RESPONSE as LTC4_3_,
        nmlnovuspa_.LTC_RESPONSE_DATETIME as LTC5_3_,
        nmlnovuspa_.RESENT_ADHOC_UUID as RESENT7_3_
    from
        MACHV.NML_NOVUS_PAYLOAD nmlnovuspa_
    where
        nmlnovuspa_.PAYLOAD_FILENAME=?
Hibernate:
    select
        nmlbatch_.BATCH_UUID,
        nmlbatch_.REQUEST_DATETIME as REQUEST2_1_
    from
        MACHV.NML_BATCH nmlbatch_
    where
        nmlbatch_.BATCH_UUID=?
Hibernate:
[b]    insert
    into
        MACHV.NML_NOVUS_PAYLOAD
        (ERROR_MESSAGE, LTC_REQUEST_DATETIME, LTC_RESPONSE, LTC_RESPONSE_DATETIME, RESENT_ADHOC_UUID, PAYLOAD_FILENAME)
    values
        (?, ?, ?, ?, ?, ?)[/b]


SQL Error:
Code:
U0013660-XPA|dev|2008-02-05 10:22:05,507|ERROR|main|ORA-01400: cannot insert NULL into ("MACHV"."NML_NOVUS_PAYLOAD"."BATCH_UUID")
Code:
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 05, 2008 12:45 pm 
Newbie

Joined: Thu Feb 15, 2007 3:32 pm
Posts: 10
Found the problem - I removed the insertable=false, updatable=false on the many-to-one...

Before:
Code:
@ManyToOne(cascade={},  fetch=FetchType.LAZY)
@JoinColumn(name="BATCH_UUID", unique=false, nullable=false, insertable=false, updatable=false)

    public NMLBatch getNmlBatch() {
        return this.nmlBatch;
    }


After:
Code:
@ManyToOne(cascade={},  fetch=FetchType.LAZY)
insertable=false, updatable=false)
@JoinColumn(name="BATCH_UUID", unique=false, nullable=false)

    public NMLBatch getNmlBatch() {
        return this.nmlBatch;
    }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.