-->
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: Error when using <any> mapping
PostPosted: Sun Jul 30, 2006 3:33 pm 
Newbie

Joined: Fri Sep 16, 2005 3:08 am
Posts: 15
Hi, all

I tried to use a <any> mapping in my program, but it keeps output (both on hibernate 3.1.3 and 3.2RC):

java.lang.ClassCastException: java.lang.String
at org.hibernate.type.ClassType.toString(ClassType.java:43)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:87)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:65)
at org.hibernate.type.AnyType.nullSafeSet(AnyType.java:136)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:1910)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:1887)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2117)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2503)


My program is like this:

Code:
/**
* @hibernate.class table="test_a" lazy="true"
*/
public class A implements Serializable {
    private Long id;
    private String name;
    /**
     * @hibernate.id generator-class="native"
     */
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    /**
     * @return
     *
     * @hibernate.property
     */
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}//class A


Code:
/**
* @hibernate.class table="test_b" lazy="true"
*/
public class B implements Serializable {
    private Long id;
    private String name;
    /**
     * @hibernate.id generator-class="native"
     */
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    /**
     * @return
     *
     * @hibernate.property
     */
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}//class B



Code:
/**
* @hibernate.class table="test_c" lazy="true"
*/
public class C {
    private Long id;
    private Object entity;
    /**
     * @hibernate.id generator-class="native"
     */
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    /**
     * @hibernate.any id-type="long" cascade="none" meta-type="java.lang.Class"
     * @hibernate.any-column name="table_name"
     * @hibernate.any-column name="entity_id"
     */
    public X getEntity() {
        return entity;
    }
    public void setEntity(X entity) {
        this.entity = entity;
    }
}//class C



Code:
    public void test() throws Exception {
        A a = new A();
        a.setName("hello from A");
       
        session.save(a);
       
        B b = new B();
        b.setName("hello from B");
       
        session.save(b);
       
        C c = new C();
        c.setEntity(a);
       
        session.save(c);
    }//test()


Can anybody give me some idea?
Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 31, 2006 1:08 am 
Newbie

Joined: Fri Sep 16, 2005 3:08 am
Posts: 15
Now I solved the problem. The problem is caused by this line:

Code:
@hibernate.any id-type="long" cascade="none" meta-type="java.lang.Class"


It should be like this:

Code:
@hibernate.any id-type="long" cascade="none" meta-type="string"


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.