-->
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.  [ 7 posts ] 
Author Message
 Post subject: Mapping an array-valued columne from Postgres.
PostPosted: Fri Jan 23, 2004 4:23 pm 
Regular
Regular

Joined: Wed Dec 31, 2003 4:26 am
Posts: 108
Location: Berkeley, CA
I've got a table named Configuration that has a values columns of type varchar[].

E.g., in PostgreSQL:

CREATE TABLE "common"."configuration"
(
"name" varchar(256)
, "values" varchar[]
, "typename" varchar(32)
, LIKE "common"."usage_tracking_columns" INCLUDING DEFAULTS
)
WITHOUT OIDS
;

And the mapping for this file (generated by middlegen + hibernate plugin) has:

<property
name="values"
type="java.sql.Array"
column="values"
length="-1"
/>

for that column. Now we I lauch a bit of a test to read from this file I get:

[java] 12:15:53,911 ERROR Configuration:250 - Could not compile the mapping document
[java] net.sf.hibernate.MappingException: Could not interpret type: java.sql.Array
[java] at net.sf.hibernate.cfg.Binder.getTypeFromXML(Binder.java:895)
[java] at net.sf.hibernate.cfg.Binder.bindSimpleValue(Binder.java:403)
[java] at net.sf.hibernate.cfg.Binder.propertiesFromXML(Binder.java:1008)
[java] at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:344)
[java] at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1204)
[java] at net.sf.hibernate.cfg.Configuration.add(Configuration.java:247)
[java] at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:281)
[java] at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:304)
[java] at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:954)
[java] at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:909)
[java] at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:845)
[java] at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:831)
[java] at com.publishworks.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:11)
[java] at com.publishworks.hibernate.test.Test1.main(Test1.java:18)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:324)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:233)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:170)
[java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:699)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:206)
[java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:115)
[java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:306)
[java] at org.apache.tools.ant.Task.perform(Task.java:401)
[java] at org.apache.tools.ant.Target.execute(Target.java:338)
[java] at org.apache.tools.ant.Target.performTasks(Target.java:365)
[java] at org.apache.tools.ant.Project.executeTarget(Project.java:1237)
[java] at org.apache.tools.ant.Project.executeTargets(Project.java:1094)
[java] at org.apache.tools.ant.Main.runBuild(Main.java:669)
[java] at org.apache.tools.ant.Main.startAnt(Main.java:220)
[java] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:215)
[java] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:90)

[java] 12:15:54,192 INFO Configuration:300 - Mapping resource: ./com/publishworks/common/Configuration.hbm.xml
[java] 12:15:54,342 ERROR Configuration:250 - Could not compile the mapping document
[java] net.sf.hibernate.MappingException: duplicate import: Configuration
[java] at net.sf.hibernate.cfg.Mappings.addImport(Mappings.java:82)
[java] at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:126)
[java] at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:217)
[java] at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1204)
[java] at net.sf.hibernate.cfg.Configuration.add(Configuration.java:247)
[java] at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:281)
[java] at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:304)
[java] at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:957)
[java] at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:909)
[java] at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:845)
[java] at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:831)
[java] at com.publishworks.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:11)
[java] at com.publishworks.hibernate.test.Test1.main(Test1.java:18)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:324)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:233)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:170)
[java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:699)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:206)
[java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:115)
[java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:306)
[java] at org.apache.tools.ant.Task.perform(Task.java:401)
[java] at org.apache.tools.ant.Target.execute(Target.java:338)
[java] at org.apache.tools.ant.Target.performTasks(Target.java:365)
[java] at org.apache.tools.ant.Project.executeTarget(Project.java:1237)
[java] at org.apache.tools.ant.Project.executeTargets(Project.java:1094)
[java] at org.apache.tools.ant.Main.runBuild(Main.java:669)
[java] at org.apache.tools.ant.Main.startAnt(Main.java:220)
[java] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:215)
[java] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:90)
[java] java.lang.ExceptionInInitializerError

Any help appreciated. Does Hibernate support the Postgres (and JDBC) array types? If so, how do I map this?

Thanks,

Ezra Epstein


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 4:31 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
This http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-450 may help.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 6:59 pm 
Regular
Regular

Joined: Wed Dec 31, 2003 4:26 am
Posts: 108
Location: Berkeley, CA
greg_barton wrote:


This is great. Thanks for that. I'm using it and get an exception, however:

[java] net.sf.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for m
ore info) setter of com.publishworks.common.Configuration.setValues

which is the property mapped to
net.sf.hibernate.ext.postgres.StringArrayType

Any clues?

== Ezra E.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 7:02 pm 
Regular
Regular

Joined: Wed Dec 31, 2003 4:26 am
Posts: 108
Location: Berkeley, CA
eepstein wrote:
[java] net.sf.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for m
ore info) setter of com.publishworks.common.Configuration.setValues


P.S., the following is in my hibernate.cfg.xml file:

<property name="hibernate.cglib.use_reflection_optimizer">false</property>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 7:24 pm 
Regular
Regular

Joined: Wed Dec 31, 2003 4:26 am
Posts: 108
Location: Berkeley, CA
OK, added

Code:
  hibernate.cglib.use_reflection_optimizer=false


as a system property, which did the trick. I now see useful information, namely:

Code:
     [java] 15:11:29,020 ERROR BasicPropertyAccessor:60 - IllegalArgumentException in class: com.publishworks.common.Configuration, setter method of proper
ty: values
     [java] 15:11:29,040 ERROR BasicPropertyAccessor:64 - expected type: net.sf.hibernate.ext.postgres.StringArrayType, actual value: [Ljava.lang.String;
     [java] net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.publishworks.common.Configuration.value
s


The thing is, I'm using hbm2java to generate the Java source code... and so the type of the "values" field is StringArrayType not String[] as expected...

I guess the manual work-around is the approach, unless there is a way to tell hbm2java to actually generate using a different type for a given field and its assoicated getter and setter methods.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 8:37 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Unfortunately I've never used those postgres types, nor the extensions I pointed you to, so I can't help much.

Quote:
The thing is, I'm using hbm2java to generate the Java source code... and so the type of the "values" field is StringArrayType not String[] as expected...

Hmmmmm... Post your mapping. You may have an error there.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 01, 2004 3:48 am 
Regular
Regular

Joined: Wed Dec 31, 2003 4:26 am
Posts: 108
Location: Berkeley, CA
greg_barton wrote:
Unfortunately I've never used those postgres types, nor the extensions I pointed you to, so I can't help much.

Quote:
The thing is, I'm using hbm2java to generate the Java source code... and so the type of the "values" field is StringArrayType not String[] as expected...

Hmmmmm... Post your mapping. You may have an error there.


SOLVED: by using the property-type meta tag:
Code:
<meta attribute="property-type">java.lang.String[]</meta>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

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.