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.