[ https://issues.apache.org/jira/browse/OPENJPA-1605?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12853978#action_12853978 ]
Leo Tu edited comment on OPENJPA-1605 at 4/6/10 2:05 PM:
---------------------------------------------------------
Hi Rick Curtis, bellow is my unit test:
(1) Create Table for Testing:
==============================================
CREATE DATABASE `abc`;
DROP TABLE IF EXISTS `abc`.`mycompany`;
CREATE TABLE `abc`.`mycompany` (
`COMPANY_ID` varchar(20) NOT NULL,
`ENGNAME` varchar(100) default NULL,
`COUNTRY` varchar(5) default NULL,
`CITY` varchar(20) default NULL,
`ZIP` varchar(10) default NULL,
`PHONE` varchar(40) default NULL,
PRIMARY KEY (`COMPANY_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `abc`.`mycompany_emp`;
CREATE TABLE `abc`.`mycompany_emp` (
`COMPANY_ID` varchar(20) NOT NULL,
`EMPNAME` varchar(50) NOT NULL default '',
`ROLE` varchar(30) default NULL,
`EMAIL` varchar(100) default NULL,
`ERP_ID` varchar(10) default NULL,
PRIMARY KEY (`COMPANY_ID`,`EMPNAME`),
CONSTRAINT `COMPANY_EMP_FK1` FOREIGN KEY (`COMPANY_ID`) REFERENCES `mycompany` (`COMPANY_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `abc`.`myrole`;
CREATE TABLE `abc`.`myrole` (
`ROLE_ID` varchar(30) NOT NULL,
`USER_ID` varchar(30) NOT NULL default '',
`IS_ENABLE` varchar(1) default NULL,
`LOCATION` varchar(30) default NULL,
PRIMARY KEY (`ROLE_ID`,`USER_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
(2) ANT build.xml for Testing:
==============================================
ant.version=[${ant.version}]
ant.java.version=[${ant.java.version}]
java.home=[${java.home}]
(3) ANT build log message for version: "openjpa-1.2.2"
(
...
...
)
==============================================
Buildfile: D:\developer\workspace-soho\magic-web\build_test.xml
[echo] ant.version=[Apache Ant version 1.7.1 compiled on June 27 2008]
[echo] ant.java.version=[1.6]
[echo] java.home=[C:\Program Files\Java\jre6]
reverse-schema-test:
[mkdir] Created dir: D:\developer\workspace-soho\magic-web\src_auto_gen_test
[delete] Deleting: D:\developer\workspace-soho\magic-web\orm.xml
[reversemappingtool] 62 server-pu INFO [main] openjpa.Tool - The reverse mapping tool will run on the database. The tool is gathering schema information; this process may take some time. Enable the org.apache.openjpa.jdbc.Schema logging category to see messages about schema data.
[reversemappingtool] 125 server-pu INFO [main] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.MySQLDictionary".
[reversemappingtool] 984 server-pu INFO [main] openjpa.Tool - ReverseMappingTool : generating classes.
[reversemappingtool] 1328 server-pu INFO [main] openjpa.Tool - Generating annotations.
[reversemappingtool] 1359 server-pu INFO [main] openjpa.MetaData - Writing class "db.model.test.Mycompany".
[reversemappingtool] 1375 server-pu INFO [main] openjpa.MetaData - Writing class "db.model.test.MycompanyEmp".
[reversemappingtool] 1375 server-pu INFO [main] openjpa.MetaData - Writing class "db.model.test.Myrole".
[reversemappingtool] 1390 server-pu INFO [main] openjpa.Tool - Writing generated class source code.
[reversemappingtool] 1390 server-pu INFO [main] openjpa.MetaData - Writing java code for generated type "db.model.test.Mycompany".
[reversemappingtool] 1406 server-pu INFO [main] openjpa.Enhance - Generating an application id for type "class db.model.test.Mycompany".
[reversemappingtool] 1453 server-pu INFO [main] openjpa.MetaData - Writing java code for generated type "db.model.test.MycompanyEmp".
[reversemappingtool] 1453 server-pu INFO [main] openjpa.Enhance - Generating an application id for type "class db.model.test.MycompanyEmp".
[reversemappingtool] 1453 server-pu INFO [main] openjpa.MetaData - Writing java code for generated type "db.model.test.Myrole".
[reversemappingtool] 1453 server-pu INFO [main] openjpa.Enhance - Generating an application id for type "class db.model.test.Myrole".
[reversemappingtool] 1468 server-pu INFO [main] openjpa.Tool - Writing generated metadata.
[reversemappingtool] 1500 server-pu INFO [main] openjpa.MetaData - Writing to file "orm.xml".
[reversemappingtool] 1515 server-pu INFO [main] openjpa.MetaData - Writing class "db.model.test.Mycompany".
[reversemappingtool] 1531 server-pu INFO [main] openjpa.MetaData - Writing class "db.model.test.MycompanyEmp".
[reversemappingtool] 1531 server-pu INFO [main] openjpa.MetaData - Writing class "db.model.test.Myrole".
BUILD SUCCESSFUL
Total time: 2 seconds
(4) ANT build log message for version: "openjpa-2.0.0-beta3"
(
...
...
)
==============================================
Buildfile: D:\developer\workspace-soho\magic-web\build_test.xml
[echo] ant.version=[Apache Ant version 1.7.1 compiled on June 27 2008]
[echo] ant.java.version=[1.6]
[echo] java.home=[C:\Program Files\Java\jre6]
reverse-schema-test:
[mkdir] Created dir: D:\developer\workspace-soho\magic-web\src_auto_gen_test
[delete] Deleting: D:\developer\workspace-soho\magic-web\orm.xml
[reversemappingtool] 93 server-pu INFO [main] openjpa.Tool - The reverse mapping tool will run on the database. The tool is gathering schema information; this process may take some time. Enable the org.apache.openjpa.jdbc.Schema logging category to see messages about schema data.
[reversemappingtool] 406 server-pu INFO [main] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.MySQLDictionary".
[reversemappingtool] 1343 server-pu INFO [main] openjpa.Tool - ReverseMappingTool : generating classes.
[reversemappingtool] 1640 server-pu INFO [main] openjpa.Tool - Generating annotations.
[reversemappingtool] 1656 server-pu INFO [main] openjpa.MetaData - Writing class "db.model.test.Mycompany".
[reversemappingtool] 1687 server-pu INFO [main] openjpa.Tool - Writing generated class source code.
[reversemappingtool] 1687 server-pu INFO [main] openjpa.MetaData - Writing java code for generated type "db.model.test.Mycompany".
[reversemappingtool] 1718 server-pu INFO [main] openjpa.Enhance - Generating an application id for type "class db.model.test.Mycompany".
[reversemappingtool] 1765 server-pu INFO [main] openjpa.Tool - Writing generated metadata.
[reversemappingtool] 1796 server-pu INFO [main] openjpa.MetaData - Writing to file "orm.xml".
[reversemappingtool] 1828 server-pu INFO [main] openjpa.MetaData - Writing class "db.model.test.Mycompany".
BUILD SUCCESSFUL
Total time: 3 seconds
(5) /META-INF/persistence.xml
==============================================
org.apache.openjpa.persistence.PersistenceProviderImpl
**********************************************
(6) Result
==> version: "openjpa-1.2.2" is correct, generate three java class files.
i.e, "Mycompany "
@Entity
@Table(name="mycompany")
@IdClass(db.model.test.Mycompany.Pk.class)
public class Mycompany {
@Basic
@Column(length=20)
private String city;
@Id
@Column(name="COMPANY_ID", length=20)
private String companyId;
@Basic
@Column(length=5)
private String country;
@Basic
@Column(length=100)
private String engname;
@OneToMany(targetEntity=db.model.test.MycompanyEmp.class, mappedBy="mycompany", cascade=CascadeType.MERGE)
private Set mycompanyEmps = new HashSet();
@Basic
@Column(length=40)
private String phone;
@Basic
@Column(length=10)
private String zip;
public Mycompany() {
}
...
}
==> version: "openjpa-2.0.0-beta3" is incorrect, generate only one file:
i.e, "Mycompany " with wrong columns
/**
* Auto-generated by:
* org.apache.openjpa.jdbc.meta.ReverseMappingTool$AnnotatedCodeGenerator
*/
@Entity
@Table(name="mycompany")
@IdClass(db.model.test.Mycompany.Pk.class)
public class Mycompany {
@Basic
@Column(length=20)
private String city;
@Id
@Column(name="COMPANY_ID", length=20)
private String companyId;
@Basic
@Column(length=5)
private String country;
@Basic
@Column(length=100)
private String email;
@Basic
@Column(nullable=false, length=50)
private String empname;
@Basic
@Column(length=100)
private String engname;
@Basic
@Column(name="ERP_ID", length=10)
private String erpId;
@Basic
@Column(name="IS_ENABLE", length=1)
private String isEnable;
@Basic
@Column(length=30)
private String location;
@Basic
@Column(length=40)
private String phone;
@Basic
@Column(length=30)
private String role;
@Basic
@Column(name="ROLE_ID", nullable=false, length=30)
private String roleId;
@Basic
@Column(name="USER_ID", nullable=false, length=30)
private String userId;
@Basic
@Column(length=10)
private String zip;
public Mycompany() {
}
...
}
was (Author: leo.tu):
Hi Rick Curtis, bellow is my unit test:
(1) Create Table for Testing:
==============================================
CREATE DATABASE `abc`;
DROP TABLE IF EXISTS `abc`.`mycompany`;
CREATE TABLE `abc`.`mycompany` (
`COMPANY_ID` varchar(20) NOT NULL,
`ENGNAME` varchar(100) default NULL,
`COUNTRY` varchar(5) default NULL,
`CITY` varchar(20) default NULL,
`ZIP` varchar(10) default NULL,
`PHONE` varchar(40) default NULL,
PRIMARY KEY (`COMPANY_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `abc`.`mycompany_emp`;
CREATE TABLE `abc`.`mycompany_emp` (
`COMPANY_ID` varchar(20) NOT NULL,
`EMPNAME` varchar(50) NOT NULL default '',
`ROLE` varchar(30) default NULL,
`EMAIL` varchar(100) default NULL,
`ERP_ID` varchar(10) default NULL,
PRIMARY KEY (`COMPANY_ID`,`EMPNAME`),
CONSTRAINT `COMPANY_EMP_FK1` FOREIGN KEY (`COMPANY_ID`) REFERENCES `mycompany` (`COMPANY_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `abc`.`myrole`;
CREATE TABLE `abc`.`myrole` (
`ROLE_ID` varchar(30) NOT NULL,
`USER_ID` varchar(30) NOT NULL default '',
`IS_ENABLE` varchar(1) default NULL,
`LOCATION` varchar(30) default NULL,
PRIMARY KEY (`ROLE_ID`,`USER_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
(2) ANT build.xml for Testing:
==============================================
ant.version=[${ant.version}]
ant.java.version=[${ant.java.version}]
java.home=[${java.home}]
(3) ANT build log message for version: "openjpa-1.2.2"
(
...
...
)
==============================================
Buildfile: D:\developer\workspace-soho\magic-web\build_test.xml
[echo] ant.version=[Apache Ant version 1.7.1 compiled on June 27 2008]
[echo] ant.java.version=[1.6]
[echo] java.home=[C:\Program Files\Java\jre6]
reverse-schema-test:
[mkdir] Created dir: D:\developer\workspace-soho\magic-web\src_auto_gen_test
[delete] Deleting: D:\developer\workspace-soho\magic-web\orm.xml
[reversemappingtool] 62 server-pu INFO [main] openjpa.Tool - The reverse mapping tool will run on the database. The tool is gathering schema information; this process may take some time. Enable the org.apache.openjpa.jdbc.Schema logging category to see messages about schema data.
[reversemappingtool] 125 server-pu INFO [main] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.MySQLDictionary".
[reversemappingtool] 984 server-pu INFO [main] openjpa.Tool - ReverseMappingTool : generating classes.
[reversemappingtool] 1328 server-pu INFO [main] openjpa.Tool - Generating annotations.
[reversemappingtool] 1359 server-pu INFO [main] openjpa.MetaData - Writing class "db.model.test.Mycompany".
[reversemappingtool] 1375 server-pu INFO [main] openjpa.MetaData - Writing class "db.model.test.MycompanyEmp".
[reversemappingtool] 1375 server-pu INFO [main] openjpa.MetaData - Writing class "db.model.test.Myrole".
[reversemappingtool] 1390 server-pu INFO [main] openjpa.Tool - Writing generated class source code.
[reversemappingtool] 1390 server-pu INFO [main] openjpa.MetaData - Writing java code for generated type "db.model.test.Mycompany".
[reversemappingtool] 1406 server-pu INFO [main] openjpa.Enhance - Generating an application id for type "class db.model.test.Mycompany".
[reversemappingtool] 1453 server-pu INFO [main] openjpa.MetaData - Writing java code for generated type "db.model.test.MycompanyEmp".
[reversemappingtool] 1453 server-pu INFO [main] openjpa.Enhance - Generating an application id for type "class db.model.test.MycompanyEmp".
[reversemappingtool] 1453 server-pu INFO [main] openjpa.MetaData - Writing java code for generated type "db.model.test.Myrole".
[reversemappingtool] 1453 server-pu INFO [main] openjpa.Enhance - Generating an application id for type "class db.model.test.Myrole".
[reversemappingtool] 1468 server-pu INFO [main] openjpa.Tool - Writing generated metadata.
[reversemappingtool] 1500 server-pu INFO [main] openjpa.MetaData - Writing to file "orm.xml".
[reversemappingtool] 1515 server-pu INFO [main] openjpa.MetaData - Writing class "db.model.test.Mycompany".
[reversemappingtool] 1531 server-pu INFO [main] openjpa.MetaData - Writing class "db.model.test.MycompanyEmp".
[reversemappingtool] 1531 server-pu INFO [main] openjpa.MetaData - Writing class "db.model.test.Myrole".
BUILD SUCCESSFUL
Total time: 2 seconds
(4) ANT build log message for version: "openjpa-2.0.0-beta3"
(
...
...
)
==============================================
Buildfile: D:\developer\workspace-soho\magic-web\build_test.xml
[echo] ant.version=[Apache Ant version 1.7.1 compiled on June 27 2008]
[echo] ant.java.version=[1.6]
[echo] java.home=[C:\Program Files\Java\jre6]
reverse-schema-test:
[mkdir] Created dir: D:\developer\workspace-soho\magic-web\src_auto_gen_test
[delete] Deleting: D:\developer\workspace-soho\magic-web\orm.xml
[reversemappingtool] 93 server-pu INFO [main] openjpa.Tool - The reverse mapping tool will run on the database. The tool is gathering schema information; this process may take some time. Enable the org.apache.openjpa.jdbc.Schema logging category to see messages about schema data.
[reversemappingtool] 406 server-pu INFO [main] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.MySQLDictionary".
[reversemappingtool] 1343 server-pu INFO [main] openjpa.Tool - ReverseMappingTool : generating classes.
[reversemappingtool] 1640 server-pu INFO [main] openjpa.Tool - Generating annotations.
[reversemappingtool] 1656 server-pu INFO [main] openjpa.MetaData - Writing class "db.model.test.Mycompany".
[reversemappingtool] 1687 server-pu INFO [main] openjpa.Tool - Writing generated class source code.
[reversemappingtool] 1687 server-pu INFO [main] openjpa.MetaData - Writing java code for generated type "db.model.test.Mycompany".
[reversemappingtool] 1718 server-pu INFO [main] openjpa.Enhance - Generating an application id for type "class db.model.test.Mycompany".
[reversemappingtool] 1765 server-pu INFO [main] openjpa.Tool - Writing generated metadata.
[reversemappingtool] 1796 server-pu INFO [main] openjpa.MetaData - Writing to file "orm.xml".
[reversemappingtool] 1828 server-pu INFO [main] openjpa.MetaData - Writing class "db.model.test.Mycompany".
BUILD SUCCESSFUL
Total time: 3 seconds
(5) /META-INF/persistence.xml
==============================================
org.apache.openjpa.persistence.PersistenceProviderImpl
> ReverseMappingTool (SchemaGenerator) bug
> ----------------------------------------
>
> Key: OPENJPA-1605
> URL: https://issues.apache.org/jira/browse/OPENJPA-1605
> Project: OpenJPA
> Issue Type: Bug
> Affects Versions: 2.0.0-beta3
> Reporter: Leo Tu
>
> org.apache.openjpa.jdbc.schema.SchemaGenerator.java
> =============================================
> ...
> ...
> public void generateTables(DBIdentifier schemaName, DBIdentifier tableName,
> Connection conn, DatabaseMetaData meta) {
> ...
> Table table;
> DBIdentifier tableSchema = DBIdentifier.NULL;
> for (int i = 0; cols != null && i < cols.length; i++) {
> if (DBIdentifier.isNull(tableName) || tableName.equals("%")) { <--- bug code line
> tableName = cols[i].getTableIdentifier(); <--- bug code line
> }
> ...
> ...
> }
> }
> if parameter tableName is null, than tableName is always been set the first column table Identifier
> --> "cols[0].getTableIdentifier() "
> this cause only generate first table class file with wrong columns.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.