Logic.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="com.hibernate.db.Logic" table="logic" schema="dbo" catalog="pubs">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="assigned" />
</id>
<property name="username" type="java.lang.String">
<column name="username" length="20" />
</property>
<property name="pwd" type="java.lang.String">
<column name="pwd" length="20" />
</property>
</class>
</hibernate-mapping>
hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="connection.username">sa</property>
<property name="connection.url">
jdbc:microsoft:sqlserver://127.0.0.1:1433
</property>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="myeclipse.connection.profile">opesna</property>
<property name="connection.password">aa</property>
<property name="connection.driver_class">
com.microsoft.jdbc.sqlserver.SQLServerDriver
</property>
<property name="max_fetch_depth">1</property>
<property name="show_sql">true</property>
<mapping resource="com/hibernate/db/Logic.hbm.xml" />
</session-factory>
</hibernate-configuration>
Logic Class have AbstractLogic
public class Logic extends AbstractLogic implements java.io.Serializable {
// Constructors
/** default constructor */
public Logic() {
}
/** minimal constructor */
public Logic(Integer id) {
super(id);
}
/** full constructor */
public Logic(Integer id, String username, String pwd) {
super(id, username, pwd);
}
}
LogicDAO Class
public class LogicDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(LogicDAO.class);
//property constants
public static final String USERNAME = "username";
public static final String PWD = "pwd";
public void save(Logic transientInstance) {
log.debug("saving Logic instance");
try {
getSession().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Logic persistentInstance) {
log.debug("deleting Logic instance");
try {
getSession().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Logic findById( java.lang.Integer id) {
log.debug("getting Logic instance with id: " + id);
try {
Logic instance = (Logic) getSession()
.get("com.hibernate.db.Logic", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Logic instance) {
log.debug("finding Logic instance by example");
try {
List results = getSession()
.createCriteria("com.hibernate.db.Logic")
.add(Example.create(instance))
.list();
log.debug("find by example successful, result size: " + results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value) {
log.debug("finding Logic instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Logic as model where model."
+ propertyName + "= ?";
Query queryObject = getSession().createQuery(queryString);
queryObject.setParameter(0, value);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List findByUsername(Object username) {
return findByProperty(USERNAME, username);
}
public List findByPwd(Object pwd) {
return findByProperty(PWD, pwd);
}
public Logic merge(Logic detachedInstance) {
log.debug("merging Logic instance");
try {
Logic result = (Logic) getSession()
.merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Logic instance) {
log.debug("attaching dirty Logic instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Logic instance) {
log.debug("attaching clean Logic instance");
try {
getSession().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
}
[/url]
|