-->
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: Mapping from List Collection to a single Column in a table
PostPosted: Thu Nov 16, 2006 6:28 am 
Newbie

Joined: Thu Nov 16, 2006 5:13 am
Posts: 1
Hibernate version: 3.2GA

I have tried to seach many places, but have not found a solution or a description of my need/problem.

I need to map a List to a single Column in a table.

The Job contains a list of Arguments, but I would like Hibernate to convert from the database column a string to a list of arguments. See this:
Code:
ID             NAME                       ARGUMENTS
1              RunJob                     [name=value];[name2=value2]
2              TestJob                    [name3=value4]

The ARGUMENTS in the database should be converted to Argument in the list. So the job named "RunJob" would contain a list of arguments:
arguments.add(new Argument("name", "value");
arguments.add(new Argument("name2", "value2");

Class data Example:
Code:
public class Job {
   private Long id;
   private String name;
   private List arguments = new ArrayList(); // Contains Argument
   
   public Long getId() {
      return id;
   }
   
   public void setId(Long id) {
      this.id = id;
   }
   
   public String getName() {
      return name;
   }
   
   public void setName(String name) {
      this.name = name;
   }
   
   public List getArguments() {
      return arguments;
   }
   
   public void setArguments(List arguments) {
      this.arguments = arguments;
   }
   
   public void addArgument(Argument argument) {
      this.arguments.add(argument);
   }
}

public class Argument {
   private String name;
   private String value;
   
   public String getName() {
      return name;
   }
   
   public void setName(String name) {
      this.name = name;
   }
   
   public String getValue() {
      return value;
   }
   
   public void setValue(String data) {
      this.value = data;
   }
}


The information I need is, what kind of best practice do I need.
Should I use:
  • org.hibernate.type.CollectionType
  • org.hibernate.type.CustomCollectionType
  • org.hibernate.type.ListType
  • org.hibernate.type.CompositeCustomType
  • org.hibernate.usertype.UserType

The only experience is: I have tried to implement a UserType so a class can have several columns in the database. But I later found out that it's better to use <component> tag in the hbm.xml file. And this is a lot different.

Now I'm asking because I have no idea how to implement this kind of mapping.


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.