-->
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: @EmbeddedId has some nullable columns
PostPosted: Tue Dec 06, 2016 4:25 pm 
Newbie

Joined: Tue Dec 06, 2016 2:20 pm
Posts: 1
Data Set

Code:
ANODE_MRID,ANODE_TYPE,ANODE_NAME,ANODE_STRT_DT_TM,ANODE_END_DT_TM,ANODE_STARTDATETIME_GMT,ANODE_ENDDATETIME_GMT,QUALIFASORDER,APNODE_MRID,APNODE_TYPE,GEN_MRID,LOAD_MRID,INTERTIE_MRID,CNODE_MRID,OFFPEAK,ONPEAK,FACTOR,PODLOSSFACTOR,MAPPING_STRT_DT_TM,MAPPING_END_DT_TM,MAPPING_STARTDATETIME_GMT,MAPPING_ENDDATETIME_GMT
RR_SS_2,POD,POD_RR2,3/31/2009,12/31/2030 11:59:59 PM,2009-03-31T07:00:00-00:00,2031-01-01T07:59:59-00:00,,,,,,,RR_7_N002,,,.347150259471503,0.00797,3/31/2009,12/31/2030 11:59:59 PM,2009-03-31T07:00:00-00:00,2031-01-01T07:59:59-00:00
RR_SS_2,POD,POD_RR2,3/31/2009,12/31/2030 11:59:59 PM,2009-03-31T07:00:00-00:00,2031-01-01T07:59:59-00:00,,,,,,,RRTT1_7_N002,,,.326424870264249,0.00801,3/31/2009,12/31/2030 11:59:59 PM,2009-03-31T07:00:00-00:00,2031-01-01T07:59:59-00:00
RR_SS_2,POD,POD_RR2,3/31/2009,12/31/2030 11:59:59 PM,2009-03-31T07:00:00-00:00,2031-01-01T07:59:59-00:00,,,,,,,RRTT2_7_N002,,,.326424870264249,0.00801,3/31/2009,12/31/2030 11:59:59 PM,2009-03-31T07:00:00-00:00,2031-01-01T07:59:59-00:00
RR_SS_2,POD,POD_RR2,3/31/2009,12/31/2030 11:59:59 PM,2009-03-31T07:00:00-00:00,2031-01-01T07:59:59-00:00,,,,DUANE_1_PL1X3,,,,,,,,4/20/2013,12/31/2030 11:59:59 PM,2013-04-20T07:00:00-00:00,2031-01-01T07:59:59-00:00



My Entity Class which maps to the view ,

Quote:
@Entity
@Table(name = "MF2_ANODE_V1_V")
@NamedQuery(name = "Anode.findAll", query = "SELECT a FROM Anode a")
public class Anode implements Serializable {

private static final long serialVersionUID = -1534272615371130692L;

@EmbeddedId
private AnodePk anodePk;

@Column(name = "ANODE_STARTDATETIME_GMT")
private String anodeStartdatetimeGmt;

@Column(name = "ANODE_ENDDATETIME_GMT")
private String anodeEnddatetimeGmt;

@Column(name = "QUALIFASORDER")
private BigInteger qualifasorder;

@Column(name = "APNODE_TYPE")
private String apnodeType;

@Column(name = "OFFPEAK")
private BigDecimal offpeak;

@Column(name = "ONPEAK")
private BigDecimal onpeak;

@Column(name = "FACTOR")
private BigDecimal factor;

@Column(name = "PODLOSSFACTOR")
private BigDecimal podlossfactor;

@Temporal(TemporalType.DATE)
@Column(name = "MAPPING_STRT_DT_TM")
private Date mappingStrtDtTm;

@Temporal(TemporalType.DATE)
@Column(name = "MAPPING_END_DT_TM")
private Date mappingEndDtTm;

@Column(name = "MAPPING_STARTDATETIME_GMT")
private String mappingStartdatetimeGmt;

@Column(name = "MAPPING_ENDDATETIME_GMT")
private String mappingEnddatetimeGmt;

@Column(name = "APNODE_MRID")
private String apnodeMrid;






My First Embeddable Class

Code:
@Embeddable
@Access(AccessType.FIELD)
public class AnodePk implements Serializable {

   /**
    *
    */
   private static final long serialVersionUID = -4870154692805156774L;

   @Column(name = "ANODE_MRID")
   private String anodeMrid;

   @Column(name = "ANODE_TYPE")
   private String anodeType;

   @Column(name = "ANODE_NAME")
   private String anodeName;

       @Column(name = "GEN_MRID")
   private String genMrid;

   @Column(name = "LOAD_MRID")
   private String loadMrid;

   @Column(name = "INTERTIE_MRID")
   private String intertieMrid;

   @Column(name = "CNODE_MRID")
   private String cnodeMrid;




if we see although i am trying to use the natural key as which is combination of the following columns in the embedable class
anodeMrid , anodeName , anodeType , ( one of the value will be present from next list of columns ) genMrid; loadMrid; intertieMrid; cnodeMrid;

The main problem is that actually each record returned by the view is natural key and unique only for following omcbninations

anodeMrid , anodeName , anodeType ,genMrid1
anodeMrid , anodeName , anodeType ,loadMrid1
anodeMrid , anodeName , anodeType ,intertieMrid
anodeMrid , anodeName , anodeType ,loadMrid2
anodeMrid , anodeName , anodeType ,cnodeMrid1

so only one field will have a value not all the others genMrid; loadMrid; intertieMrid; cnodeMrid; for each record .

Please suggest what is the best way to implement that scenerios.

Right now Hibenrate returns 5 rows but all the data populated is as below.

anodeMrid , anodeName , anodeType ,genMrid1
anodeMrid , anodeName , anodeType ,genMrid1
anodeMrid , anodeName , anodeType ,genMrid1
anodeMrid , anodeName , anodeType ,genMrid1

assume that i Have implemented equals methods .

thanks
Sanjay Gautam


Top
 Profile  
 
 Post subject: Re: @Embeddable has some column nullable
PostPosted: Wed Dec 07, 2016 4:30 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
For a composite Primary Key, every individual column must be NOT NULL.

The Hibernate identifier is no different because the identifier value must be unique. Only NOT NULL columns can guarantee uniqueness. Hence, you need to reconsider your database schema.


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.