1
votes

I want try to make hibernate save my object but with wrappered data type, not general data tipe like int, String etc. Example, like class Contact below:

public class Contact {
 private StringWrapper firstName;
 private StringWrapper lastName;
 private StringWrapper email;
 private IntegerWrapper id;


 public StringWrapper getEmail() {
  return email;
 }


 public StringWrapper getFirstName() {
  return firstName;
 }


 public StringWrapper getLastName() {
  return lastName;
 }


 public void setEmail(StringWrapper StringWrapper) {
  email = StringWrapper;
 }


 public void setFirstName(StringWrapper StringWrapper) {
  firstName = StringWrapper;
 }


 public void setLastName(StringWrapper StringWrapper) {
  lastName = StringWrapper;
 }


 public IntegerWrapper getId() {
  return id;
 }


 public void setId(IntegerWrapper i) {
  id = i;
 }

}

I have value in that class that saved in StringWrapper and IntegerWrapper object. I must use getString() method in StringWrapper and getInteger() in IntegerWrapper to get actual value.

Is posible for me, to save object with hibernate, but the values that want to save can get with call getString() and getInteger() method before? Because, if i force to save with hibernate i will get message "Could not determine type for: StringWrapper, at table contact for columns ......"

Thanks,

1

1 Answers

0
votes

You are looking for a @Converter. Define one for each of your XXWrapper-classes and you will be able to use them in your entity classes as much as you like. A short example of how to do that can be found here (and by a simple search for "JPA converter"):

http://www.thoughts-on-java.org/2013/10/jpa-21-how-to-implement-type-converter.html