-->
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.  [ 5 posts ] 
Author Message
 Post subject: ant, annotation config & missing named queries
PostPosted: Mon Dec 28, 2009 12:32 pm 
Newbie

Joined: Mon Feb 02, 2009 2:49 pm
Posts: 15
I am using ant and hibernate tools 3.2.5.beta (best version I can find) to do reverse engineering.

Step 1, reverse engineer database into hbm files with <jdbcconfiguration> and <hbm2hbmxml>.
Step 2, using <configuration>, generate annotated java files with <hbm2java>, and a cfg file for annotations with <hbm2cfgxml>.
Step 3, using <annotationconfiguration>, generate Spring DAOs with <hbmtemplate>.

All works well, except that if in between step 2 and 3, I put a named query into a entity pojo, <annotationconfiguration> doesn't pick it up.

When I edit the hbmxml file to add the query instead of the entity pojo and use the <configuration>, the queries are picked up. It makes me think that it is <annotationconfiguration> that is failing me. One thing that casts doubt on that is that I see the following logging statement when it is running:
Code:
INFO - Binding Named query: findAllSubsetsX => from Subset


But like I say, it doesn't show up in the DAO.

So, thinking it was my custom template, I switch to using <hbm2dao> with the same results. If fact I also copied the dao ftl file
Code:
<#foreach queryName in cfg.namedQueries.keySet()>

but with no change.

I am pretty committed to using annotated pojos, but if I must, I might make an xml file with the queries and use xsl to massage the hbmxml files.

I have also tried using javax.persistence.NamedQuery, org.hibernate.annotations.NamedQuery. Tried wrapping the single query in @NamedQueries, etc.

Is this something that doesn't work?

Also, problem #2 (and related to my complex reverse engineering scheme) the jira ticket for cascades is fixed (version 3.2.4.GA). I have cascading foreign keys in my database but I don't see them in the annotations. Do I not know how to use this? (edit: jira ticket HBX-623)

Thanks, as always.

Jeff


Top
 Profile  
 
 Post subject: Re: ant, annotation config & missing named queries
PostPosted: Mon Dec 28, 2009 3:44 pm 
Newbie

Joined: Mon Feb 02, 2009 2:49 pm
Posts: 15
I just love replying to my own posts....

I finally found some mention of this type or problem and the solution was to fully qualify the query name.

So now, the query resolves, but parameters are a problem for both my template and the built-in one (dao/daohome.ftl).

My query looks like this:
Code:
@NamedQuery(name="navy.selbd.hibernate.model.Subset.findAllSubsetsX", query="from Subset")


And I get this error. Same thing happens whether I have parameters to the query or not.

Quote:
[hibernatetool] ERROR -
[hibernatetool] Error on line 229, column 1 in dao/daohome.ftl
[hibernatetool] cfg.namedQueries.get(queryName).parameterTypes is undefined.
[hibernatetool] It cannot be assigned to params
[hibernatetool] The problematic instruction:
[hibernatetool] ----------
[hibernatetool] ==> assignment: params=cfg.namedQueries.get(queryName).parameterTypes [on line 229, column 1 in dao/daohome.ftl]


Everything works fine if, in my template, I take out all mention of params and its assignment.

Thanks.


Top
 Profile  
 
 Post subject: Re: ant, annotation config & missing named queries
PostPosted: Mon Dec 28, 2009 6:35 pm 
Newbie

Joined: Mon Feb 02, 2009 2:49 pm
Posts: 15
So, some fun facts about this problem is that the <configuration>, one, doesn't require a fully qualified query name and the <annotationconfiguration> does. Great, things to know. I think it has to do with jpa consistency. But, two, the <configuration> bindery returns an empty list for the parameter types and <annotationconfiguration> returns null, which makes the template fail. That seems like a bug that would have come up before.

Also, this is consistent whether or not I have parameters in the query. With <configuration> it doesn't fail, but I get no parameters on the named query, just an empty list. Here is my query. I've tried with a question mark and with a named parameter. Not sure what I'm missing at this point.

Code:
<query name="findAllSubsetsX">from Subset s where s.subsetId = :sss</query>


So, unsolved questions:
  • annotationconfiguration produces null, whereas configuration produces empty list on named queries
  • cascading delete from reverse engineering? Am I mistaken that it should be already fixed.
  • where did my parameters go?

Thanks.


Top
 Profile  
 
 Post subject: Re: ant, annotation config & missing named queries
PostPosted: Tue Mar 02, 2010 1:28 pm 
Newbie

Joined: Mon Mar 01, 2010 7:17 am
Posts: 10
Hi,

I think I've been having the problem as you do. I created a related post:

viewtopic.php?f=1&t=1002952

Did ever come to find a solution?

Thanks.

Regards,
Nuno Guerreiro


Top
 Profile  
 
 Post subject: Re: ant, annotation config & missing named queries
PostPosted: Tue Mar 02, 2010 1:37 pm 
Newbie

Joined: Mon Feb 02, 2009 2:49 pm
Posts: 15
nmd.guerreiro wrote:
Hi,

I think I've been having the problem as you do. I created a related post:

viewtopic.php?f=1&t=1002952

Did ever come to find a solution?

Thanks.

Regards,
Nuno Guerreiro


Sorry, no resolution. I've abandoned trying to reverse engineer for now, in part, because of these problems. I am now doing Pojo-first--starting with java classes that have annotations. This is pretty good for me, I get the java code that I really want (still working out code generation issues), but the database schema generated by SchemaExport is very minimal. Some reasons for this are the platform dependent nature of database object creation, but there could be more support for the "name" type of attribute parameters that JPA and Hibernate support. For instance, you can name a @UniqueConstraint in the name parameter, but it doesn't get propagated to the ddl generated.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.