2007/3/19, Max Rydahl Andersen <[EMAIL PROTECTED]>:
jdk5 does autoboxing, older jdk's does not.
So int into an Integer fails.
(please note i'm an unexperienced java dev)
I produced the patch (using "svn diff"), at least it compiles now.
Probably the same function toWrapperClass() in BasicPOJOClass.java is
not needed but i didn't understand how it does work getJavaTypeClass
in that class so i was more conservative (you surely know how to cut
it and retain only the version of Cfg2JavaTool.java).
I have 2 more question, if you have time to respond me:
1) Now that compiles, can i trust this interface? Is there some usage
documentation about it (can't found it in hibernate manuals)?
2) I see that a "List findAll()" method is not provided (sort of
"select * from Table"). How can i obtain it in the right (and quick)
way?
For the patch, if it's ok, license is obviously lgpl and i give the
copyright to you.
Thanks,
Francesco
Index: src/java/org/hibernate/tool/hbm2x/Cfg2JavaTool.java
===================================================================
--- src/java/org/hibernate/tool/hbm2x/Cfg2JavaTool.java (revisione 11296)
+++ src/java/org/hibernate/tool/hbm2x/Cfg2JavaTool.java (copia locale)
@@ -471,4 +471,37 @@
public boolean isArray(String typeName) {
return typeName!=null && typeName.endsWith("[]");
}
+
+ /**
+ * Called for compatibility with jdk1.4, that doesn't support autoboxing of types
+ *
+ */
+ public String toWrapperClass(Property p) {
+ String javaTypeName= this.getJavaTypeName(p,false);
+ if(javaTypeName.equals("boolean")) {
+ return "new Boolean(id)";
+ }
+ if(javaTypeName.equals("byte")) {
+ return "new Byte(id)";
+ }
+ if(javaTypeName.equals("short")) {
+ return "new Short(id)";
+ }
+ if(javaTypeName.equals("int")) {
+ return "new Integer(id)";
+ }
+ if(javaTypeName.equals("long")) {
+ return "new Long(id)";
+ }
+ if(javaTypeName.equals("float")) {
+ return "new Float(id)";
+ }
+ if(javaTypeName.equals("double")) {
+ return "new Double(id)";
+ }
+ if(javaTypeName.equals("char")) {
+ return "new Character(id)";
+ }
+ return "id";
+ }
}
Index: src/java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java
===================================================================
--- src/java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java (revisione 11296)
+++ src/java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java (copia locale)
@@ -875,4 +875,36 @@
}
}
+ /**
+ * Called for compatibility with jdk1.4, that doesn't support autoboxing of types
+ *
+ */
+ public String toWrapperClass(Property p) {
+ String javaTypeName= this.getJavaTypeName(p,false);
+ if(javaTypeName.equals("boolean")) {
+ return "new Boolean(id)";
+ }
+ if(javaTypeName.equals("byte")) {
+ return "new Byte(id)";
+ }
+ if(javaTypeName.equals("short")) {
+ return "new Short(id)";
+ }
+ if(javaTypeName.equals("int")) {
+ return "new Integer(id)";
+ }
+ if(javaTypeName.equals("long")) {
+ return "new Long(id)";
+ }
+ if(javaTypeName.equals("float")) {
+ return "new Float(id)";
+ }
+ if(javaTypeName.equals("double")) {
+ return "new Double(id)";
+ }
+ if(javaTypeName.equals("char")) {
+ return "new Character(id)";
+ }
+ return "id";
+ }
}
Index: src/templates/dao/daohome.ftl
===================================================================
--- src/templates/dao/daohome.ftl (revisione 11296)
+++ src/templates/dao/daohome.ftl (copia locale)
@@ -58,7 +58,7 @@
public ${declarationName} findById( ${pojo.getJavaTypeName(clazz.identifierProperty, jdk5)} id) {
log.debug("getting ${declarationName} instance with id: " + id);
try {
- ${declarationName} instance = entityManager.find(${pojo.getDeclarationName()}.class, id);
+ ${declarationName} instance = entityManager.find(${pojo.getDeclarationName()}.class, <#if jdk5>id<#else>${pojo.toWrapperClass(clazz.identifierProperty)}</#if>);
log.debug("get successful");
return instance;
}
@@ -148,7 +148,7 @@
log.debug("getting ${declarationName} instance with id: " + id);
try {
${declarationName} instance = (${declarationName}) sessionFactory.getCurrentSession()
- .get("${clazz.entityName}", id);
+ .get("${clazz.entityName}", <#if jdk5>id<#else>${c2j.toWrapperClass(clazz.identifierProperty)}</#if>);
if (instance==null) {
log.debug("get successful, no instance found");
}
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
hibernate-devel mailing list
hibernate-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hibernate-devel