composite-id + hibernate

hello frnd,

i give more about my prblm....

this is code that i fetch record...(main)

//--

xml_config xConfig = new xml_config();

Criteria cri = session.createCriteria(xml_config.class);

String s="CA";

//Query q = session.createQuery("from xml_config config where config.country_cd='CA'");

cri.add(Restrictions.like("country_cd", s));

cri.add(Restrictions.like("Dtd_version", "1.0"));

List q = cri.list();//error line by eclipse ide

Iterator itr = q.iterator();

ArrayList<String> v = new ArrayList<String>();

while(itr.hasNext())

{

xConfig = (zespl_xml_config)itr.next();

v.add(xConfig.getDtd_FileName());

System.out.println("ICH FLAG "+xConfig.getICHFlag());

System.out.println("Dtd file Name "+xConfig.getDtd_FileName());

}

//-

and this my mapping file

//--

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC

"-//Hibernate/Hibernate Mapping DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="HibernateUtil.zespl_xml_config" table="zespl_gifnoc_lmx">

<composite-id>

<key-property name="country_cd" column="dc_yrtnuoc"/>

<key-property name="Dtd_type" column="epyt_dtd"/>

<key-property name="Dtd_version" column="noisrev_dtd"/>

<key-property name="Dtd_FileName" column="eman_elif_dtd"/>

</composite-id>

<property name="ICHFlag" column="galf_hci"/>

<property name="xls_FileName" column="eman_elif_lsx"/>

</class>

</hibernate-mapping>

//

and the output errror is ......

//--

Hibernate: select this_.dc_yrtnuoc as dc1_0_, this_.epyt_dtd as epyt2_0_, this_.noisrev_dtd as noisrev3_0_, this_.eman_elif_dtd as eman4_0_, this_.dc_yrtnuoc as dc1_1_0_, this_.epyt_dtd as epyt2_1_0_, this_.noisrev_dtd as noisrev3_1_0_, this_.eman_elif_dtd as eman4_1_0_, this_.galf_hci as galf5_1_0_, this_.eman_elif_lsx as eman6_1_0_ from zespl_gifnoc_lmx this_ where this_.dc_yrtnuoc like ? and this_.noisrev_dtd like ?

java.lang.ClassCastException: HibernateUtil.xml_config

at org.hibernate.loader.Loader.getKeyFromResultSet(Lo ader.java:650)

at org.hibernate.loader.Loader.getRowFromResultSet(Lo ader.java:277)

at org.hibernate.loader.Loader.doQuery(Loader.java:38 4)

at org.hibernate.loader.Loader.doQueryAndInitializeNo nLazyCollections(Loader.java:203)

at org.hibernate.loader.Loader.doList(Loader.java:149 9)

at org.hibernate.loader.Loader.list(Loader.java:1482)

at org.hibernate.loader.criteria.CriteriaLoader.list( CriteriaLoader.java:111)

at org.hibernate.impl.SessionImpl.list(SessionImpl.ja va:1246)

at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl. java:299)

at HibernateDemo.Main.main(Main.java:87)

and my java bean is...

//

public class xml_config

{

String country_cd;

String ICHFlag;

String Dtd_type;

String Dtd_version;

String Dtd_FileName;

String xls_FileName;

public String getCountry_cd() {

return country_cd;

}

public void setCountry_cd(String country_cd) {

this.country_cd = country_cd;

}

public String getDtd_FileName() {

return Dtd_FileName;

}

public String getDtd_type() {

return Dtd_type;

}

public String getDtd_version() {

return Dtd_version;

}

public String getICHFlag() {

return ICHFlag;

}

public String getXls_fileName() {

return xls_FileName;

}

public void setDtd_FileName(String dtd_FileName) {

Dtd_FileName = dtd_FileName;

}

public void setDtd_type(String dtd_type) {

Dtd_type = dtd_type;

}

public void setDtd_version(String dtd_version) {

Dtd_version = dtd_version;

}

public void setICHFlag(String flag) {

ICHFlag = flag;

}

public String getXls_FileName() {

return xls_FileName;

}

public void setXls_FileName(String xls_FileName) {

this.xls_FileName = xls_FileName;

}

}

//

if any one have solution then please help me...

thanx and regards,

PanDev84

Message was edited by:

pandev84

[4416 byte] By [pandev84a] at [2007-11-27 7:31:36]
# 1
java.lang.ClassCastException: HibernateUtil.xml_configThis means that the given class cannot be casted (to the class as you have definied in the mapping, which is HibernateUtil.zespl_xml_config).
BalusCa at 2007-7-12 19:11:51 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

You've specified a criteria object for xml_config objects, but your mapping is of zesp_xml_config objects. They aren't the same and you can't cast the latter into the former.

And what's with all the reversed column names? That's one of the stupidest naming approaches I've ever seen, and I've seen some prizewinners.

dcmintera at 2007-7-12 19:11:51 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

hello,

thanx for valuable guideline

but after changing code problem remains same...

if i use normal <id> it works properly but when i use <composite-id>

it dosen't works..

please tell what r conditions to use <composite-id>

i have only one table with four primary keys no relation to other tables like forign key..

no depedancy..

pls help me and give proper solution to solve my problem.

thanx in advance..

PanDev84

pandev84a at 2007-7-12 19:11:51 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

> And what's with all the reversed column names? That's

> one of the stupidest naming approaches I've ever

> seen, and I've seen some prizewinners.

Can you please get this addressed?

I am going to go further then Dave and say that's horrific ****. Just terrible.

Fix that nonsense please. Just thinking of the poor sap who would be maintaining your app and having to deal with that garbage gives me an ulcer.

cotton.ma at 2007-7-12 19:11:51 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
?!?siht ekil gnidaer ekil uoy od ,naem I
cotton.ma at 2007-7-12 19:11:51 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

> thanx for

If you can't be bothered to spell out words like "thanks" and "please" I don't see why I should spell out answers for you.

> but after changing code

To what? I AM NOT PSYCHIC.

> problem remains same...

If you have the same problem, you have the same bug. Your code is wrong in the same way. Perhaps you didn't compile the new code? I don't know.

If you have a different problem, you have a different bug. I haven't seen your code, and you haven't described the problem or pasted the error messages. I have no idea what the problem is.

> please tell what r conditions to use <composite-id>

The fields have to collectively form a primary key. That's the only condition.

> i have only one table with four primary keys no

Four primary key fields. It's impossible to have multiple primary keys in a table.

> pls help me and give proper solution to solve my

> problem.

"That didn't work, I did something, fix it?" I'm becoming disinclined to help someone who's being quite this unhelpful.

And what is with the naming convention? What on earth posessed you to do that?

D. (quite cranky today).

dcmintera at 2007-7-12 19:11:51 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...