-->
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.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Validator Resource Bundles And Hibernate Tool
PostPosted: Mon Mar 13, 2006 11:38 am 
Newbie

Joined: Thu Dec 01, 2005 12:23 pm
Posts: 19
Hi folks,

I'm currently experiencing some problems when I try to use my custom propertie file, respectively resource bundle for the Hibernate validators. The problems that occur concern the Hibernate Tool:

First on the <annotationconfiguration> the full qualified filename must be set for the propertie file/resource bundle, like "myproperties_en.properties". So here it is not really possible to specifiy a real resource bundle where I just can pass the base file name (here: "myproperties.properties").

Second is, when I add an Hibernate validator for a property like this:

Code:
@Length(min = 2, max = 30, message = "{err.msg.length}")
private String name;


And then try to generate the database schema using the Hibernate Tool ant task <hbm2ddl> following error occurs:

Code:
java.lang.IllegalArgumentException: could not instantiate ClassValidator
        at org.apache.tools.ant.Task.perform(Task.java:373)
        at org.apache.commons.jelly.tags.ant.AntTag.doTag(AntTag.java:195)
        at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:247)
        at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95)
        at org.apache.commons.jelly.TagSupport.invokeBody(TagSupport.java:186)
        at org.apache.commons.jelly.tags.util.AvailableTag.doTag(AvailableTag.java:68)
        at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:247)
        at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95)
        at org.apache.maven.jelly.tags.werkz.MavenGoalTag.runBodyTag(MavenGoalTag.java:78)
        at org.apache.maven.jelly.tags.werkz.MavenGoalTag$MavenGoalAction.performAction(MavenGoalTag.java:109)
        at org.apache.maven.werkz.Goal.fire(Goal.java:656)
        at org.apache.maven.werkz.Goal.attain(Goal.java:592)
        at org.apache.maven.werkz.WerkzProject.attainGoal(WerkzProject.java:210)
        at org.apache.maven.jelly.tags.werkz.MavenAttainGoalTag.doTag(MavenAttainGoalTag.java:114)
        at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:247)
        at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95)
        at org.apache.maven.jelly.tags.werkz.MavenGoalTag.runBodyTag(MavenGoalTag.java:78)
        at org.apache.maven.jelly.tags.werkz.MavenGoalTag$MavenGoalAction.performAction(MavenGoalTag.java:109)
        at org.apache.maven.werkz.Goal.fire(Goal.java:656)
        at org.apache.maven.werkz.Goal.attain(Goal.java:592)
        at org.apache.maven.plugin.PluginManager.attainGoals(PluginManager.java:693)
        at org.apache.maven.MavenSession.attainGoals(MavenSession.java:263)
        at org.apache.maven.cli.App.doMain(App.java:511)
        at org.apache.maven.cli.App.main(App.java:1258)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at com.werken.forehead.Forehead.run(Forehead.java:551)
        at com.werken.forehead.Forehead.main(Forehead.java:581)
Caused by: java.lang.IllegalArgumentException: could not instantiate ClassValidator
        at org.hibernate.validator.ClassValidator.createValidator(ClassValidator.java:204)
        at org.hibernate.validator.ClassValidator.createMemberValidator(ClassValidator.java:165)
        at org.hibernate.validator.ClassValidator.initValidator(ClassValidator.java:134)
        at org.hibernate.validator.ClassValidator.<init>(ClassValidator.java:83)
        at org.hibernate.validator.ClassValidator.createChildValidator(ClassValidator.java:156)
        at org.hibernate.validator.ClassValidator.initValidator(ClassValidator.java:136)
        at org.hibernate.validator.ClassValidator.<init>(ClassValidator.java:83)
        at org.hibernate.validator.ClassValidator.<init>(ClassValidator.java:72)
        at org.hibernate.validator.ClassValidator.<init>(ClassValidator.java:64)
        at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:669)
        at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:276)
        at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:210)
        at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:996)
        at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:56)
        at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:179)
        at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:43)
        at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:143)
        at org.apache.tools.ant.Task.perform(Task.java:364)
        ... 29 more
Caused by: java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key err.msg.length
        at java.util.ResourceBundle.getObject(ResourceBundle.java:325)
        at java.util.ResourceBundle.getObject(ResourceBundle.java:322)
        at java.util.ResourceBundle.getString(ResourceBundle.java:285)
        at org.hibernate.validator.ClassValidator.replace(ClassValidator.java:404)
        at org.hibernate.validator.ClassValidator.createValidator(ClassValidator.java:199)
        ... 46 more


The key definitely is set in the property file. So any suggestions how I could get <hbm2ddl> to work? Or is this some kind of bug?

Regards,
bitbyter

PS: Hope this is the right place for the posting.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 12:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
How are you invoking the hibernatetool ?

There is no resource bundle built in/needed there, so just curious on why you talk about specifying it ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 3:55 pm 
Newbie

Joined: Thu Dec 01, 2005 12:23 pm
Posts: 19
I'm invoking the Hibernate Tool from within an Ant task, respectively a maven goal using the Ant plugin like this:

Code:
<ant:hibernatetool destdir="${maven.build.dir}">
  <annotationconfiguration configurationfile="hibernate.cfg.xml" propertyfile="myproperties.properties" />
  <hbm2ddl export="false" console="true" update="false" drop="false" create="true" outputfilename="ddl.sql" delimiter=";"/>
</ant:hibernatetool>


Acutally I'm also curious why the <hbm2dll> task requires a resource bundle/property file containing the error message keys from a ClassValidator.

I wonder what I'm doing wrong...


- bitbyter


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 4:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
propertyfile is a hibernate.properties file - nothing to do with resource messages.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 4:25 pm 
Newbie

Joined: Thu Dec 01, 2005 12:23 pm
Posts: 19
The same problem remains when I do not specify any property file like this:

Code:
<annotationconfiguration configurationfile="hibernate.cfg.xml" />


So I'm still wondering why the DDL can't be generated using the Hibernate Tool.

- bitbyter


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 4:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
for some reason Validator is not looking up the message in its defaullt resource bundle. have you changed the resource bundle and is the changed resource bundle in the classpath of the hibernatetool ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 5:03 pm 
Newbie

Joined: Thu Dec 01, 2005 12:23 pm
Posts: 19
Is it possible to change the resource bundle?
The documentation only mentions that it is possible to use an own resource bundle programatically. But how to specify the resource bundle when using/calling <hmb2ddl> task?

Assume this is the problem.

- bitbyter


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 3:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
i'll need to ask emmmanuel how the validator expect to get its values for the resource bundle....

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 6:25 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
There was a bug in 3.1beta8 regarding the classloader used
http://opensource2.atlassian.com/projec ... se/ANN-256

I now use the context classloader and then the ClassValidator classloader to load the user resource bundle.

err.msg.length is not part of the default resource bundle so a ValidatorMessages.properties file has to be present in your classpath.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 6:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ok that explains it.

You might be able to workaround this bug in beta8 by making the ValidatorMessages.properties avaiable in the classpath used for the taskdef.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 8:17 am 
Newbie

Joined: Thu Dec 01, 2005 12:23 pm
Posts: 19
Thanks for the information. I'll try that with the ValidatorMessage.properties file.

So I assume it is not possible to freely choose the name for the resource bundle? Because I'd like to have a single resource bundle that also includes other values beside the Hibernate validator messages. Is it possible to define the resource bundle name, for example by using a Hibernate properties file in <annotationconfiguration>?

- bitbyter


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 8:42 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I'm considering this but that's not easy.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 15, 2006 9:49 am 
Newbie

Joined: Thu Dec 01, 2005 12:23 pm
Posts: 19
Using the predfined "ValidatorMessages.properties" file seems to work if it is placed on the root directory of a classpath entry. If it is placed on a subdirectory/subpackage of a classpath entry it does not work. I assume this is some kind of bug, as I would expect that a resource bundle can be placed anywhere within a classpath entry.

Furthermore I'm wondering why the <hbm2ddl> database schema generator requires any of the validator resource bundles? Wouldn't it make sense to remove this kind of restriction? At least this would allow to name the validator resource bundle freely.

- bitbyter


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 15, 2006 1:23 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
bitbyter wrote:
Using the predfined "ValidatorMessages.properties" file seems to work if it is placed on the root directory of a classpath entry. If it is placed on a subdirectory/subpackage of a classpath entry it does not work. I assume this is some kind of bug, as I would expect that a resource bundle can be placed anywhere within a classpath entry.


Wrong assumption - a resource (no matter what kind) needs to be uniquely named. It would be extremely inefficient to scan all "subdirs".

Quote:
Furthermore I'm wondering why the <hbm2ddl> database schema generator requires any of the validator resource bundles? Wouldn't it make sense to remove this kind of restriction? At least this would allow to name the validator resource bundle freely.


Well, hbm2ddl require to load the classes and call buildMappings() on annotation configuration. I do not know why it in this process has to initialize the validator things. but is that a big issue for you since you just have to put the correct things in the classpath.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 25, 2006 8:26 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
bitbyter wrote:
Using the predfined "ValidatorMessages.properties" file seems to work if it is placed on the root directory of a classpath entry. If it is placed on a subdirectory/subpackage of a classpath entry it does not work. I assume this is some kind of bug, as I would expect that a resource bundle can be placed anywhere within a classpath entry.

No this is not the way resource bundle are defined in Java, that actually would be really abd and lead to inconsistency if 2 fils share the same names.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 16 posts ]  Go to page 1, 2  Next

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.