-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to map Java 5 generic types?
PostPosted: Fri Jul 07, 2006 3:26 am 
Newbie

Joined: Thu Jul 06, 2006 6:35 am
Posts: 1
Hi all,

I'd like to map a class that is generic type with hibernate 3. Is that possible?

Example of the class:

Code:
public class MyClass<T> {

   public T getValue()...

   public void setValue(T value)...
}


How can I map the method set/getValue? Do I need to write a UserType for that or is there a "built in" solution available in Hibernate?

Thank you a lot.

PS: The search function of the forum doesn't work properly. It displays the first page of result but when I click at "next page" it says that it couldn't find matches.

Regards
Steph


Top
 Profile  
 
 Post subject: Abstraction
PostPosted: Fri Jul 07, 2006 4:04 am 
Beginner
Beginner

Joined: Thu Jul 06, 2006 11:09 pm
Posts: 25
You can make an abstract parameterized class. For example, here's a Person object class:

Code:
public abstract class Person<ID extends Serializable> {
  ID id;
  String name;
  Date birthDate;

  public abstract ID getId();
  public abstract void setId(ID id);

  //getXxx() and setXxxx() here.
}


When you create an Employee class (also a Person), do it like this:

Code:
public class Employee extends Person<Integer> {
   Integer id;
   
   public Integer getId() {
      return this.id;
   }

   public void setId(Integer id) {
      this.id = id;
   }
   //inherited name, birthDate properties and accessors;
}


Or, a UserLogin class for authentication:

Code:
public class User extends Person<String> {

  private String id;
 
  public String getId() {
    return this.id;
  }

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

  ... //the rest of the code.
}


This is not always applicable to every entity class.


Top
 Profile  
 
 Post subject: Re: How to map Java 5 generic types?
PostPosted: Mon Feb 15, 2010 8:33 am 
Newbie

Joined: Mon Jul 13, 2009 9:00 am
Posts: 7
And how what does mapping code look like? I'm having the same issue as the one who opened the thread. I've already written the code, but for some reason Hibernate can't map those objects to their corresponding table fields.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.