-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Creating tables without mapping objects
PostPosted: Wed Apr 30, 2008 6:05 pm 
Newbie

Joined: Wed Apr 30, 2008 5:22 pm
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.