Author: dgeraskov
Date: 2009-10-23 10:14:49 -0400 (Fri, 23 Oct 2009)
New Revision: 18263
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfo.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/ConfigurationActor.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5052
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfo.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfo.java 2009-10-23
14:08:14 UTC (rev 18262)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfo.java 2009-10-23
14:14:49 UTC (rev 18263)
@@ -263,7 +263,8 @@
while (it.hasNext()) {
String name = it.next();
String check = name.toLowerCase();
- if ("id".equalsIgnoreCase(check)) { //$NON-NLS-1$
+ if ("id".equalsIgnoreCase(check) //$NON-NLS-1$
+ || "identity".equalsIgnoreCase(check)) { //$NON-NLS-1$
primaryIdName = name;
break;
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/ConfigurationActor.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/ConfigurationActor.java 2009-10-23
14:08:14 UTC (rev 18262)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/ConfigurationActor.java 2009-10-23
14:14:49 UTC (rev 18263)
@@ -35,6 +35,7 @@
import org.eclipse.jdt.core.dom.QualifiedType;
import org.eclipse.jdt.core.dom.SimpleType;
import org.eclipse.jdt.core.dom.Type;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.eclipse.jdt.core.dom.WildcardType;
import org.hibernate.FetchMode;
@@ -266,11 +267,36 @@
@Override
public boolean visit(CompilationUnit node) {
- Assert.isNotNull(rootClass);
+ Assert.isNotNull(rootClass);
return true;
}
@SuppressWarnings("unchecked")
+ public boolean visit(TypeDeclaration node) {
+ if ("".equals(entityInfo.getPrimaryIdName())){ //$NON-NLS-1$
+ //try to guess id
+ FieldDeclaration[] fields = node.getFields();
+ String firstFieldName = ""; //$NON-NLS-1$
+ for (int i = 0; i < fields.length; i++) {
+ Iterator<VariableDeclarationFragment> itFieldsNames =
fields[i].fragments().iterator();
+ while(itFieldsNames.hasNext()) {
+ VariableDeclarationFragment field = itFieldsNames.next();
+ if ("id".equals(field.getName().getIdentifier()) //$NON-NLS-1$
+ || "identity".equals(field.getName().getIdentifier())){ //$NON-NLS-1$
+ entityInfo.setPrimaryIdName(field.getName().getIdentifier());
+ return true;
+ } else if ("".equals(firstFieldName)){ //$NON-NLS-1$
+ //set first field as id
+ firstFieldName = field.getName().getIdentifier();
+ }
+ }
+ }
+ entityInfo.setPrimaryIdName(firstFieldName);
+ }
+ return true;
+ }
+
+ @SuppressWarnings("unchecked")
public boolean visit(FieldDeclaration node) {
Type type = node.getType();
if (type == null) {