• Post Reply Bookmark Topic Watch Topic
  • New Topic

Complex Objects with Hibernate

 
Falc Norman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I want to save complex Objects from Flex in a Database with Life Cycle Data Services and Hibernate (if possible, with the LCDS HibernateAssembler) but i have some questions about it.

Example:
I want to save the mx.controls.DataGrid Class from Flex because I want to save all individual changes from a special DataGrid.
For this, I have to write a ActionScript Class with all attributes from the DataGrid and a similar Class in Java with (setter and getter).

My first question is, how can I save the complex attributes in Java? I tried to save them as lava.lang.Object but then i get the error:

org.hibernate.MappingException: identifier mapping has wrong number of columns: MyGrid type: object

My second questions is, how can i create the Java Class and/or the Database very fast with tools?



thanks for help.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want ot save the DataGrid itself, rather than the dataProvider? Or am I missunderstanding what you are up to?


org.hibernate.MappingException: identifier mapping has wrong number of columns: MyGrid type: object

The error message suggests you have mapped an identifier with the wrong number of columns,. Can you post your mapping?


My second questions is, how can i create the Java Class and/or the Database very fast with tools?

Personally I wouldn't let Hibernate generate DDL, I'd model this myself first. But Hibernate will do it if you want it to - see the hbb2ddl property in the Hibernate configuration. The Hibernate website lists a bunch of tools for other generation.
 
Falc Norman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I want to save the DataGrid itself. (saving style options etc...)
Saving a small self-created DataProvider Object works fine.


Because I read something about the Hibernate hbm2ddl tool and creating the DB with it, I use the HibernateAnnotationsAssembler.
I reduced the Java Class and Database to one attribute for testing and to find errors.

Java Class with Annotations:


Data-Management-Config.xml


hibernate.cfg.xml


if i set the accessibilityProperties attribute within the Java Class to "String" or "int" i get no error so maybe "Object" don´t work. But I have no idea how to save a complex attribute other than as a Object.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does your accessibilityProperties actually contain? Assuming this is just the accessibilityProperties associated with your DataGrid component this will have a bunch of values. Hibernate is going to have to know how to turn that bunch of properties into a data type that can be persisted on the database (you could just persist it as is as a BLOB, but a BLOB primary key is not a good idea). Also, if you are using accessibilityProperties as a key are you not running the risk of duplicate keys? If you need to persist an object other than those normally supported by SQL data types you'll need to write a custom UserType to do it.
 
Falc Norman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your help Paul.

accessibilityProperties is type of flash.accessibility.AccessibilityProperties, so you can see the DataGrid is a complex object and i don´t want to describe every attribute.

The accessibilityProperties attribute is not realy the primary key, I only defined it because I needed one defined for hibernate and I just wanted to test it with one attribute.

I added a "@Lob" tag to the attribute and defined it in the database as BLOB but still i get the same error.

Maybe i have to add another tag to my attribute?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to use a LOB you'll need to make sure the type is one Hibernate can translate to a LOB, e.g. a byte array. If you don't have that I suspect you may need a custom UserType. I don't think Hibernate klnows what to do with something as generic as an Object.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!