3

I have created a custom data type in the database.This custom datatype has 5 different properties from different tables and I have database function which returns this custom data type.

Could someone please let me know how to map this custom data type with the corresponding Java object in hibernate?

Waiting for your reply.

Thanks.

3
  • Which db? Is your custom data type in the db or in Java? Commented Apr 16, 2011 at 0:43
  • what kind of custom data type do you want to add ? Commented Apr 16, 2011 at 7:39
  • @edalorza :Sorry for not being clear .. I am using the PostGres DB. I have created my own data type using the following query CREATE TYPE MyCustomDataType AS (f1 int, f2 text,....); I have a created a SQL function as shown below CREATE FUNCTION myFunctionName(int) RETURNS MyCustomDataType As you can see its returning MyCustomDataType.My question is once I invoke this function in the java-hibernate code , how can I map MyCustomDataType to corresposding Java model in hibernate ? I know mappping of db table to java objec Commented Apr 16, 2011 at 15:37

1 Answer 1

3

It is indeed a little unclear what you mean. I believe that a custom data type, or user type, (in the universe of Hibernate) relates to a single database field/column. Say you wanted to have your entities use a special type of ID, then you would create a custom user type which could take care of serializing/deserializing the ID. Here's a link to more on how you write your own user type: http://blog.xebia.com/2009/11/understanding-and-writing-hibernate-user-types/

However, you say that you have created several tables which this data type is to use. Then I'd say you simply need to look into how for instance mapping files work. There are great tutorials out there, and Hibernate has a good one too: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html.

Edit:

Have a look at https://forum.hibernate.org/viewtopic.php?p=2370886. It seems that someone has asked a similar question at the Hibernate forum. I hope it can take you in the right direction. If the forum posting itself doesn't give you an answer, then see if you can contact the person who asked the forum question.

Sign up to request clarification or add additional context in comments.

2 Comments

@edalorza :Sorry for not being clear .. I am using the PostGres DB. I have created my own data type using the following query CREATE TYPE MyCustomDataType AS (f1 int, f2 text,....); I have created a SQL function as shown below CREATE FUNCTION myFunctionName(int) RETURNS MyCustomDataType As you can see its returning MyCustomDataType.My question is once I invoke this function in the java-hibernate code , how can I map MyCustomDataType to corresposding Java model in hibernate ?
I see. I'm not too familiar with how that works since I've never actually worked with PostGres myself. However, have a look at the link I've posted above and see if that can guide you in the right direction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.