-->
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.  [ 11 posts ] 
Author Message
 Post subject: @Version on non-default property from jdbcconfiguration
PostPosted: Thu Oct 19, 2006 6:11 am 
Hi,

I've got a sparkly new oracle database and I'm having a go at generating EJB3 entities from the database using the tools in hibernate 3.2.beta8.

It is working ok (in that java classess with the correct EJB3 entity annotations are created) - with one exception...

The @Version annotation is not being created in the entities.

The field we are using for optimistic locking is an int called LOCK_SEQ (the name VERSION is already taken for domain specific stuff).

I have a simple ReverseEngineeringStrategy which includes:

Code:
public static final String COL_OPTIMISTIC_LOCK = "LOCK_SEQ";

public String getOptimisticLockColumnName(TableIdentifier identifier) {
  System.out.println("called getOptimisticLockColumnName on table: " + identifier.getName() );
      
  return COL_OPTIMISTIC_LOCK;
}
   
  public boolean useColumnForOptimisticLock(TableIdentifier identifier, String column) {
  boolean optLock = false;
  System.out.println("into useColumnForOptimisticLock for column: "         +       column);
  if (COL_OPTIMISTIC_LOCK.equals(column)){
    optLock = true;
    System.out.println("column: " + column + " is used for optimistic lock.");
  } else {
    System.out.println("column: " + column + " is not used for optimistic lock.");
      }
  return optLock;
}


I think this is working fine as it also has getTableIdentifierStrategyName and getTableIdentifierProperties which are working as expected.

The tools are run from as an ant task:

Code:
<hibernatetool destdir="${hbm-output-dir}" templatepath="${basedir}/templates/tools-jar">      

  <jdbcconfiguration
   propertyfile="./hibernate.properties"
   packagename="com.the.customer.entity.thing"
   revengfile="${basedir}/conf/hbm-tools/reveng.xml"
   reversestrategy="com.the.customer.bootstrap.reveng.MetadataEntityRevEngStrategy"
   detectOptimisticLock="true"
  />
         
  <hbm2java jdk5="true" ejb3="true"></hbm2java>
         
</hibernatetool>


Is it expected that the @Version annotation should be created under these conditions? If so, any suggestions where I should be looking to see why it isn't? I've had a bit of a look around but seem to be missing the connection between starting to generate a pojo and pulling in the template "fragments" for an ejb3 entity...

Thanks,

Andy


Top
  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 6:26 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
i think there is a bug in jira for it already; but it is not yet fixed.

If you want to have a go at it then you need to look into EntityPojoClass and its "annotation" related methods.

Annotation generation is currently done mainly in code since it requires some transformation/processing that is not really maintainable in templates.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 6:38 am 
Doh, fogot to check jira before posting - sorry.

It looks like:

http://opensource.atlassian.com/project ... se/HBX-688

is a similar issue, although the issue is raised against generating from hbm.xml files rather than a database - which I guess indicates that the problem is in the java code generation side rather than the model creation.

I'll take a look at EntityPojoClass.java...

Cheers,

Andy


Top
  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 6:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes it is in annoation code generation; the model works fine (since hbm.xml generation has it correctly)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 11:54 am 
How about this approach...

I've added the following couple of methods to EntityPOJOClass.java:

Code:
public boolean isOptimisticLockProperty(Property property) {
   boolean isOptLockProp = false;
   //System.out.println("is opt lock on prop: " + property.getName());
   PersistentClass pClass = property.getPersistentClass();
   if (pClass != null) {
      Property vProp = pClass.getVersion();
      //System.out.println("Persistent class is: " + pClass.getEntityName() + ", version property: " + vProp);
      if (property.equals(vProp)) {
         isOptLockProp = true;
      }
   } else {
      System.out.println("null pClass!");
   }
   System.out.println("Property: " + property.getName() + " is opt lock: " + isOptLockProp);
   return isOptLockProp;
}
   
public String getOptimisticLockAnnotation(Property property) {
   String verAnnStr = null;
   importType("javax.persistence.Version");
   importType("javax.persistence.Column");
   PersistentClass pClass = property.getPersistentClass();
   Iterator colIttr = property.getColumnIterator();
   if (colIttr.hasNext()) {
      Column col = (Column) colIttr.next();
      verAnnStr = "@Version\n@Column(name=\"" + col.getName() + "\")";
   }
   return verAnnStr;
}



I also modified Ejb3PropertyGetAnnotation.ftl:

Code:
<#--TODO support optional and targetEntity-->   
${pojo.generateJoinColumnsAnnotation(property)}
<#elseif c2h.isCollection(property)>
${pojo.generateCollectionAnnotation(property, cfg)}
<#-- is this the optimistic lock version property? -->
<#elseif pojo.isOptimisticLockProperty(property)>
// this should be the lock property
${pojo.getOptimisticLockAnnotation(property)}
<#else>
${pojo.generateBasicAnnotation(property)}
${pojo.generateAnnColumnAnnotation(property)}
</#if>


So that my new methods are called.

It seems to work...

Cheers,

Andy


Top
  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 12:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
looks sensible...but maybe it could be merged into generateBasicAnnotation so you reused the generateAnnColumnAnnotation for this ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 20, 2006 3:57 am 
Ahh, yes - it probably should be, would mean less changes overall.

I'll try to do that this afternoon (need to do some "proper" work right now).

While I think about it - if I'm generating a sub-class, are only the properties declared in the sub-class going to be generated, allowing properties from the parent to be inherited. Perhaps I should just go and look at the code... ;)

Cheers,

Andy


Top
  
 
 Post subject:
PostPosted: Fri Oct 20, 2006 4:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
i would need to do the same so let me know what you find ;)

but I don't think annotations codegeneration have good inheritance generation yet.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: This bug is too old, there is a patch, but still not fixed
PostPosted: Fri May 25, 2007 11:55 am 
Beginner
Beginner

Joined: Thu Aug 04, 2005 8:41 pm
Posts: 47
JIRA HBX-942

Please, get it fixed
Thanks


Top
 Profile  
 
 Post subject: Annotations bug
PostPosted: Fri May 25, 2007 11:58 am 
Beginner
Beginner

Joined: Thu Aug 04, 2005 8:41 pm
Posts: 47
And there is similar bug open for that

http://opensource.atlassian.com/project ... se/HBX-688

hbm2java is not generating the @Version annotation for the <version ...> element

with patch pending


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 9:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
"Please, get it fixed" is not really an encouragement that works....

Anyhow its fixed now because HBX-942 where done with code AND test :)

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.