Hi,
I new in hibernate, and i have searched a way for create a Table without mapping an object, i need to create tables programaticaly (dynamically) just from a Dialect.I found this code, but here the code creates a mapping to an object (Objective.class), and i dont want any objects for my tables.
code:
[b]public void create(){
Dialect dialect = Dialect.getDialect();
//create table object
Table table = new Table();
table.setName("Objectives");
Column column_id = new Column("id");
Column column_name = new Column("name");
//create columns in the table
column_id.setSqlType(dialect.getTypeName(java.sql.Types.INTEGER));
column_name.setSqlType(dialect.getTypeName(java.sql.Types.VARCHAR));
//create values for the columns
SimpleValue value_int = new SimpleValue(table);
SimpleValue value_char = new SimpleValue(table);
//set the types to values
value_int.setTypeName(dialect.getTypeName(java.sql.Types.INTEGER));
value_char.setTypeName(dialect.getTypeName(java.sql.Types.VARCHAR));
//mapping values to columns
value_int.addColumn(column_id);
value_char.addColumn(column_name);
//Creating new Property "id" and set value type
Property property1 = new Property();
property1.setName("id");
property1.setValue(value_int);
//Creating new Property "name" and set value type
Property property2 = new Property();
property2.setName("Name");
property2.setValue(value_char);
//Creat Root class and set the class of interest which needs to be persisted
RootClass pClass = new RootClass();
pClass.setEntityPersisterClass(Objective.class);
//set table to the root class
pClass.setTable(table);
//Add properteis to the class
pClass.addProperty(property1);
pClass.addProperty(property2);
Table mappingTable = new Table();
mappingTable.setName("OBJECTIVE_MAPPING");
Set childObjectives = new Set(pClass);
childObjectives.setTypeName("childObjectives");
childObjectives.setCollectionTable(mappingTable);
childObjectives.setLazy(true);
childObjectives.setOrphanDelete(true);
// //....
// //cfg.createMappings().addClass(clazz);
} [/b]
Could you please help me in this.
Thanks in advance..
Jorge
|