Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Friday, November 23, 2007

java code for Key Int Auto Increment

import org.hibernate.Session;

import util.ConnectionUtil;
import util.HibernateUtil;

public class Main {
static Session session;

public static void main(String[] args) {
open();

Keyword k = new Keyword();
session.save(k);
session.flush();

close();
}


private static void open() {
ConnectionUtil.openConnection();
ConnectionUtil.update("CREATE TABLE KEYWORDS ( ID int, NAME VARCHAR(25) )");
session = HibernateUtil.currentSession();
}

private static void close() {
ConnectionUtil.closeConnection();
HibernateUtil.closeSession();
HibernateUtil.sessionFactory.close();
}
}



/////////////////////////////////////////////////////////////////////////

public class Keyword {

protected Integer id_;
protected String name_ ="aaa";

public Keyword() {
}

public Integer getId() {
return id_;
}

public void setId(Integer newId) {
this.id_ = newId;
}

public String getName() {
return name_;
}

public void setName(String newName) {
this.name_ = newName;
}
}



/////////////////////////////////////////////////////////////////////////


"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">









column="NAME"
not-null="true"
unique="true"
/>







/////////////////////////////////////////////////////////////////////////


"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">




org.hsqldb.jdbcDriver
jdbc:hsqldb:mem:testdb
sa



2


org.hibernate.dialect.HSQLDialect


true





No comments: