-->
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: UserType. How to do whithout a table?
PostPosted: Tue Dec 26, 2006 3:06 am 
Newbie

Joined: Tue Dec 26, 2006 2:17 am
Posts: 1
Hi everybody!

I have some question about a UserType.

I need these Type:
Code:
public class A {
  private int id;
  private int name;
}

and it uses:
Code:
public class B {
  private int id;
  private A a;
}

If I kept A in a separate table a with the fields: "ID, Name", I would do the following:
Code:
<hibernate-mapping>
  <class name="B" table="b">
    <id name="id">
      <generator class="native"/>
    </id>
    <many-to-one name="a" column="a_id" class="A"/>
  </class>
<hibernate-mapping>

But I want to do that without a table a and with a static consts in A, like this:
Code:
public final class A {
    public static final A A_1 = new A(1,"str1");
    public static final A A_2 = new A(2,"str2");
    private int id;
    private String name;
    ...
}

and when a hibernate loading some B he uses well-defined staic const from A

Thx a lot for help!

...and sorry for my english :(


Top
 Profile  
 
 Post subject: Don't use many-to-one
PostPosted: Wed Jan 03, 2007 10:55 am 
Regular
Regular

Joined: Wed Aug 24, 2005 11:49 am
Posts: 63
You need to create usertype and map the property as a 'normal' column (no many-to-one is needed).

In the usertype, you translate between the db-value and your constant (and the other way around)

Edwin

_________________
Edwin van der Elst
Finalist IT Group


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.