Hi akumar, What exactly were you expecting from the reverse mapping tool? Were you expecting that the @org.apache.openjpa.persistence.jdbc.Index annotations to be inserted into the generated java files? Or, were you expecting something else? You mentioned unique and non-unique keys... But, the primary key is detected correctly with the @Id annotation generation. I'm guessing you meant unique and non-unique indexes...
If you were expecting the @Index annotation, per the documentation, this annotation was really meant for the other direction. That is, it's used as a hint for OpenJPA when generating the database schema [1]: "..OpenJPA uses index information during schema generation to index the proper columns." And, even the Reverse Mapping tool is not meant to be the end-all game [2]: "..Examine the generated class, metadata, and mapping information, and modify it as necessary. Remember that the reverse mapping tool only provides a starting point, and you are free to make whatever modifications you like to the code it generates." Not saying that this process couldn't be enhanced as a feature request, but I don't think there's a bug in the processing. Good luck, Kevin [1] http://openjpa.apache.org/builds/latest/docs/docbook/manual.html#ref_guide_mapping_jpa_constraints [2] http://openjpa.apache.org/builds/latest/docs/docbook/manual.html#ref_guide_pc_reverse <http://openjpa.apache.org/builds/latest/docs/javadoc/org/apache/openjpa/persistence/jdbc/Index.html> On Thu, Dec 6, 2012 at 9:00 AM, anand213 <[email protected]>wrote: > Hi, > I am trying to reverse map beans by directly connecting to H2 DB. Below is > the DB schema to reverse. It has couple of unique keys and a non-unique > key. > These are read by the tool but no annotations generated for the same: > > CREATE SCHEMA TEST; > > CREATE TABLE TEST.EMPLOYEE_FOR_CACHE ( > ID INT PRIMARY KEY, > FNAME VARCHAR2(50), > LNAME VARCHAR2(50), > PROJECT VARCHAR2(10), > DEPT VARCHAR2(50), > LOCATION VARCHAR2(50) > ); > > -- Indexes: > CREATE INDEX ON TEST.EMPLOYEE_FOR_CACHE(LNAME); > CREATE UNIQUE INDEX ON TEST.EMPLOYEE_FOR_CACHE(FNAME, LNAME, LOCATION); > CREATE UNIQUE INDEX ON TEST.EMPLOYEE_FOR_CACHE(DEPT, PROJECT); > > > Below is the generated bean: > @Entity > @Table( name="EMPLOYEE_FOR_CACHE") > public class EmployeeForCache { > @Basic > @Column(length=50) > private String dept; > > @Basic > @Column(length=50) > private String fname; > > @Id > private int id; > > @Basic > @Column(length=50) > private String lname; > > @Basic > @Column(length=50) > private String location; > > @Basic > @Column(length=10) > private String project; > > > public EmployeeForCache() { > } > > public EmployeeForCache(int id) { > this.id = id; > } > > public String getDept() { > return dept; > } > > public void setDept(String dept) { > this.dept = dept; > } > > public String getFname() { > return fname; > } > > public void setFname(String fname) { > this.fname = fname; > } > > public int getId() { > return id; > } > > public void setId(int id) { > this.id = id; > } > > public String getLname() { > return lname; > } > > public void setLname(String lname) { > this.lname = lname; > } > > public String getLocation() { > return location; > } > > public void setLocation(String location) { > this.location = location; > } > > public String getProject() { > return project; > } > > public void setProject(String project) { > this.project = project; > } > } > > > > Below are the logs: > > 94 cut-jpa-bean-generator TRACE [main] openjpa.jdbc.Schema - Found > existing index "INDEX_14" on table "TEST.EMPLOYEE_FOR_CACHE (FNAME)". > 94 cut-jpa-bean-generator TRACE [main] openjpa.jdbc.Schema - Found > existing index "INDEX_14" on table "TEST.EMPLOYEE_FOR_CACHE (LNAME)". > 94 cut-jpa-bean-generator TRACE [main] openjpa.jdbc.Schema - Found > existing index "INDEX_14" on table "TEST.EMPLOYEE_FOR_CACHE (LOCATION)". > 94 cut-jpa-bean-generator TRACE [main] openjpa.jdbc.Schema - Found > existing index "INDEX_14C" on table "TEST.EMPLOYEE_FOR_CACHE (DEPT)". > 94 cut-jpa-bean-generator TRACE [main] openjpa.jdbc.Schema - Found > existing index "INDEX_14C" on table "TEST.EMPLOYEE_FOR_CACHE (PROJECT)". > 94 cut-jpa-bean-generator TRACE [main] openjpa.jdbc.Schema - Found > existing index "PRIMARY_KEY_1" on table "TEST.EMPLOYEE_FOR_CACHE (ID)". > 94 cut-jpa-bean-generator TRACE [main] openjpa.jdbc.Schema - Found > existing index "INDEX_1" on table "TEST.EMPLOYEE_FOR_CACHE (LNAME)". > 94 cut-jpa-bean-generator TRACE [main] openjpa.jdbc.Schema - Reading > foreign keys for schema name "TEST", table name "TEST.EMPLOYEE_FOR_CACHE". > 109 cut-jpa-bean-generator INFO [main] openjpa.Tool - > ReverseMappingTool > : generating classes. > 107259 cut-jpa-bean-generator INFO [main] openjpa.Tool - Generating > annotations. > 110368 cut-jpa-bean-generator INFO [main] openjpa.Tool - Writing > generated class source code. > > > > I am using below reverse properties: > -pkg, com.bofa.cut.jpa.entity.bean, -directory, ./scr/test/java, -log, > 'DefaultLevel=WARN, Tool=INFO, SQL=TRACE,Schema=TRACE', -metadata, none, > -useGenericCollections, true, -annotations, true, -connectionURL, ..... > > OPen JPA version: 2.2.0 > > Thanks and Regards, > AKumar > > > > -- > View this message in context: > http://openjpa.208410.n2.nabble.com/Unique-constraint-annotations-not-generated-by-Reverse-Mapping-tool-tp7582055.html > Sent from the OpenJPA Users mailing list archive at Nabble.com. >
