ï»??xml version="1.0" encoding="utf-8" standalone="yes"?>日韩高清国产一区在线,中文字幕一区二区三区在线不卡 ,青青青手机在线视频观看http://www.aygfsteel.com/supercrsky/category/27643.html专注于JavaWebå¼€å?/description>zh-cnWed, 23 Sep 2009 12:17:28 GMTWed, 23 Sep 2009 12:17:28 GMT60åŸÞZºŽæŒ‰annotationçš„hibernate主键生成½{–ç•¥http://www.aygfsteel.com/supercrsky/articles/296122.html々上善若水ã€?/dc:creator>々上善若水ã€?/author>Wed, 23 Sep 2009 02:00:00 GMThttp://www.aygfsteel.com/supercrsky/articles/296122.htmlhttp://www.aygfsteel.com/supercrsky/comments/296122.htmlhttp://www.aygfsteel.com/supercrsky/articles/296122.html#Feedback0http://www.aygfsteel.com/supercrsky/comments/commentRss/296122.htmlhttp://www.aygfsteel.com/supercrsky/services/trackbacks/296122.html阅读全文

]]>
Hibernate二çñ”¾~“存详解http://www.aygfsteel.com/supercrsky/articles/238580.html々上善若水ã€?/dc:creator>々上善若水ã€?/author>Tue, 04 Nov 2008 05:50:00 GMThttp://www.aygfsteel.com/supercrsky/articles/238580.htmlhttp://www.aygfsteel.com/supercrsky/comments/238580.htmlhttp://www.aygfsteel.com/supercrsky/articles/238580.html#Feedback0http://www.aygfsteel.com/supercrsky/comments/commentRss/238580.htmlhttp://www.aygfsteel.com/supercrsky/services/trackbacks/238580.html阅读全文

]]>
åŸÞZºŽJPAçš„CRUD(OneToMany)http://www.aygfsteel.com/supercrsky/articles/164302.html々上善若水ã€?/dc:creator>々上善若水ã€?/author>Fri, 30 Nov 2007 07:42:00 GMThttp://www.aygfsteel.com/supercrsky/articles/164302.htmlhttp://www.aygfsteel.com/supercrsky/comments/164302.htmlhttp://www.aygfsteel.com/supercrsky/articles/164302.html#Feedback0http://www.aygfsteel.com/supercrsky/comments/commentRss/164302.htmlhttp://www.aygfsteel.com/supercrsky/services/trackbacks/164302.html阅读全文

]]>
åŸÞZºŽJPAçš„Hibernate->CRUD(½Ž€å•应ç”?(原创)http://www.aygfsteel.com/supercrsky/articles/163902.html々上善若水ã€?/dc:creator>々上善若水ã€?/author>Thu, 29 Nov 2007 01:08:00 GMThttp://www.aygfsteel.com/supercrsky/articles/163902.htmlhttp://www.aygfsteel.com/supercrsky/comments/163902.htmlhttp://www.aygfsteel.com/supercrsky/articles/163902.html#Feedback0http://www.aygfsteel.com/supercrsky/comments/commentRss/163902.htmlhttp://www.aygfsteel.com/supercrsky/services/trackbacks/163902.html 脚本如下:
use test;
create table person
(
 id 
int AUTO_INCREMENT primary key,
 username 
varchar(20),
 password 
varchar(20)
);

insert into person values(null,'ts','ts');
实体¾cȝ”¨Annotation映射,代替hbm.
package com.vo;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@SuppressWarnings(
"unchecked""serial" })
@Entity 
//标识是一个实�/span>
@Table(name="person"//映射�/span>
public class Person implements Serializable
{
    
//主键映射
    @Id
    
//主键自增
    @GeneratedValue(strategy=GenerationType.AUTO)
    
private Integer id;
    
//@Column(name="username"),对于åˆ?可映ž®„也可以不映ž®?注意保持列名和属性名一致就è¡?nbsp;
    private String username;
    
private String password;

    
public Integer getId()
    
{
        
return id;
    }


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


    
public String getUsername()
    
{
        
return username;
    }


    
public void setUsername(String username)
    
{
        
this.username = username;
    }


    
public String getPassword()
    
{
        
return password;
    }


    
public void setPassword(String password)
    
{
        
this.password = password;
    }

}


hibernate.cfg.xml配置文äšg:
<?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"
>
<hibernate-configuration>
    
<session-factory>
        
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        
<property name="connection.url">jdbc:mysql://localhost:3306/test</property>
        
<property name="connection.username">root</property>
        
<property name="connection.password">root</property>
        
<property name="show_sql">true</property>
        
<!-- å®žä½“¾cÀL˜ ž®?nbsp;-->
        
<mapping class="com.vo.Person"/>
    
</session-factory>
</hibernate-configuration>    
‹¹‹è¯•¾c?
package com.test;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import com.vo.Person;

public class PersonTest
{
    
private Session session;
    
private Transaction tx;

    @Before
    
public void before()
    
{
        session 
= new AnnotationConfiguration().configure()
                .buildSessionFactory().openSession();
        tx 
= session.getTransaction();
    }


    @After
    
public void after()
    
{
        session.close();
    }


    @Test
    
public void testSave()
    
{
        tx.begin();
        Person person 
= new Person();
        person.setUsername(
"zdw");
        person.setPassword(
"admin");
        session.save(person);
        tx.commit();
    }

    
    @Test
    
public void testUpdate()
    
{
        tx.begin();
        Person person 
= (Person) session.load(Person.class1);
        person.setPassword(
"test");
        session.update(person);
        tx.commit();
    }

    @SuppressWarnings(
"unchecked")
    @Test
    
public void testQueryAll()
    
{
        List
<Person> persons = session.createCriteria(Person.class).list();
        assertNotNull(persons);
    }

    
    @Test
    
public void testDelete()
    
{
        Person person 
= (Person) session.load(Person.class1);
        session.delete(person);
    }

}

¾læµ‹è¯?增删æ”ÒŽŸ¥å…¨éƒ¨æ­£å¸¸.
˜q™æ ·çš„确很方便了.
源码可以在我的网盘下è½? ç‚ÒŽ­¤ä¸‹è²

]]>
Ö÷Õ¾Ö©Öë³ØÄ£°å£º ¿ªÆ½ÊÐ| ÇàÍ­Ï¿ÊÐ| ¶õÍпËǰÆì| µÀæÚÏØ| ¸ßÑôÏØ| ¶«ÄþÏØ| ÁÙÏÄÏØ| ¾¸½­ÊÐ| ¶Ø»¯ÊÐ| ¸ßÌ¨ÏØ| ÑÓÊÙÏØ| ¶ÀÉ½ÏØ| ¹ÅÀËÏØ| ·¿²ú| ¸ßÒØÏØ| ÒË´ºÊÐ| Æ½Ô­ÏØ| ÄþÑôÏØ| ¿ª·âÊÐ| ¾Å½­ÏØ| ƽºþÊÐ| ¼ÎÏéÏØ| ºÓÇúÏØ| ÃÏ´å| ÄÚÇðÏØ| Ôª½­| ½¶ÁëÏØ| ¼´Ä«ÊÐ| ÁøÁÖÏØ| Ö麣ÊÐ| ´óͬÊÐ| Îä¸ÔÊÐ| ¹Ê³ÇÏØ| ´óÒ±ÊÐ| ·ïÇìÏØ| кÓÏØ| Äþ¹úÊÐ| ÇàÑôÏØ| ¶õÖÝÊÐ| л¯ÏØ| ±£É½ÊÐ|