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: Criteria for fetching @EmbeddedId objects
PostPosted: Tue Dec 22, 2009 11:19 pm 
Newbie

Joined: Tue Dec 22, 2009 10:37 pm
Posts: 1
Hi,

We have created the following table structure.

CREATE TABLE REF_CODES
(
DOMAIN VARCHAR2(100 BYTE) NOT NULL,
CODE VARCHAR2(50 BYTE) NOT NULL,
SHORT_DESC VARCHAR2(255 BYTE) NOT NULL,
LONG_DESC VARCHAR2(255 BYTE),
DELETE_IND VARCHAR2(1 BYTE),
)


CREATE INDEX REF_CODES_UK ON _CODES
(DOMAIN, CODE)

ALTER TABLE REF_CODES ADD (
CONSTRAINT REF_CODES_UK1
UNIQUE (DOMAIN, CODE));

We have used Hibernate Annotation Classes and generated the POJOs for the table. The Generated Annotation classes were named as ReferenceCodes, ReferenceCodesId. Following is the code


@Entity
@Table(name="REF_CODES"
,schema="HR"
)

public class ReferenceCodes implements java.io.Serializable {


// Fields

private ReferenceCodesId id;


// Constructors

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


/** full constructor */
public ReferenceCodes(ReferenceCodesId id) {
this.id = id;
}


// Property accessors
@EmbeddedId

@AttributeOverrides( {
@AttributeOverride(name="domain", column=@Column(name="DOMAIN", nullable=false, length=100) ),
@AttributeOverride(name="code", column=@Column(name="CODE", nullable=false, length=50) ),
@AttributeOverride(name="shortDesc", column=@Column(name="SHORT_DESC", nullable=false) ),
@AttributeOverride(name="longDesc", column=@Column(name="LONG_DESC") ),
@AttributeOverride(name="deleteInd", column=@Column(name="DELETE_IND", length=1) ),
} )

public ReferenceCodesId getId() {
return this.id;
}

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












/**
* ReferenceCodesId entity. @author MyEclipse Persistence Tools
*/
@Embeddable
public class ReferenceCodesId implements java.io.Serializable {


// Fields

private String domain;
private String code;
private String shortDesc;
private String longDesc;
private String deleteInd;


// Constructors

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

/** minimal constructor */
public ReferenceCodesId(String domain, String code, String shortDesc) {
this.domain = domain;
this.code = code;
this.shortDesc = shortDesc;
}

/** full constructor */
public ReferenceCodesId(String domain, String code, String shortDesc, String longDesc, String deleteInd) {
this.domain = domain;
this.code = code;
this.shortDesc = shortDesc;
this.longDesc = longDesc;
this.deleteInd = deleteInd;
}


// Property accessors

@Column(name="DOMAIN", nullable=false, length=100)

public String getDomain() {
return this.domain;
}

public void setDomain(String domain) {
this.domain = domain;
}

@Column(name="CODE", nullable=false, length=50)

public String getCode() {
return this.code;
}

public void setCode(String code) {
this.code = code;
}

@Column(name="SHORT_DESC", nullable=false)

public String getShortDesc() {
return this.shortDesc;
}

public void setShortDesc(String shortDesc) {
this.shortDesc = shortDesc;
}

@Column(name="LONG_DESC")

public String getLongDesc() {
return this.longDesc;
}

public void setLongDesc(String longDesc) {
this.longDesc = longDesc;
}

@Column(name="DELETE_IND", length=1)

public String getDeleteInd() {
return this.deleteInd;
}

public void setDeleteInd(String deleteInd) {
this.deleteInd = deleteInd;
}

===========================================================================

We have written a DAOImpl class and the following criteria is fetching only null objects. It would be great help for us if you provide a quick solution.

public List<ReferenceCodes> getAllRefCodes()
{
Session session = getExistingHibernateSession(true);
Criteria criteria = session.createCriteria(ReferenceCodes.class);
return criteria.list();
}


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.