溫馨提示:您的每一次轉(zhuǎn)載,體現(xiàn)了我寫此文的意義!!!煩請您在轉(zhuǎn)載時注明出處http://www.aygfsteel.com/sxyx2008/謝謝合作!!!

          雪山飛鵠

          溫馨提示:您的每一次轉(zhuǎn)載,體現(xiàn)了我寫此文的意義!!!煩請您在轉(zhuǎn)載時注明出處http://www.aygfsteel.com/sxyx2008/謝謝合作!!!

          BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
            215 Posts :: 1 Stories :: 674 Comments :: 0 Trackbacks

          #

          Exception in thread "main" java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

          不合法的狀態(tài),beanFactory沒有初始化或者關(guān)閉,在上下文中刷新。

          解決方法:ApplicationContext context = new ClassPathXmlAppliction("這里的參數(shù)沒有寫");


          posted @ 2010-10-14 13:28 雪山飛鵠 閱讀(7359) | 評論 (0)編輯 收藏


          實體
          Husband
          package com.hibernate.one2one.bean;

          import javax.persistence.Column;
          import javax.persistence.Entity;
          import javax.persistence.GeneratedValue;
          import javax.persistence.GenerationType;
          import javax.persistence.Id;
          import javax.persistence.OneToOne;
          import javax.persistence.PrimaryKeyJoinColumn;
          import javax.persistence.Table;

          @Entity
          @Table(name
          ="husband")
          public class Husband {
              
              
          private int id;
              
          private String name;
              
          private Wife wife;
              @Id
              @GeneratedValue(strategy
          =GenerationType.AUTO)
              @Column(name
          ="id")
              
          public int getId() {
                  
          return id;
              }
              
          public void setId(int id) {
                  
          this.id = id;
              }
              @Column(name
          ="name")
              
          public String getName() {
                  
          return name;
              }
              
          public void setName(String name) {
                  
          this.name = name;
              }
              @OneToOne
              @PrimaryKeyJoinColumn
              
          public Wife getWife() {
                  
          return wife;
              }
              
          public void setWife(Wife wife) {
                  
          this.wife = wife;
              }
              
          }
          Wife
          package com.hibernate.one2one.bean;

          import javax.persistence.Column;
          import javax.persistence.Entity;
          import javax.persistence.Id;
          import javax.persistence.OneToOne;
          import javax.persistence.PrimaryKeyJoinColumn;
          import javax.persistence.Table;

          @Entity
          @Table(name
          ="wife")
          public class Wife {
              
              
          private int id;
              
          private String name;
              
          private Husband husband;
              @Id
              @Column(name
          ="id")
              
          public int getId() {
                  
          return id;
              }
              
          public void setId(int id) {
                  
          this.id = id;
              }
              @Column(name
          ="name")
              
          public String getName() {
                  
          return name;
              }
              
          public void setName(String name) {
                  
          this.name = name;
              }
              @OneToOne(optional
          =false)
              @PrimaryKeyJoinColumn
              
          public Husband getHusband() {
                  
          return husband;
              }
              
          public void setHusband(Husband husband) {
                  
          this.husband = husband;
              }
              
          }
          溫馨提示:注意wife.java里面的@OneToOne(optional=false)   optional=false  屬性會在wife這端添加一個外鍵約束
          添加上上述屬性使用hbm2ddl導(dǎo)出表,打印出的sql語句
          alter table wife 
                  
          drop 
                  
          foreign key FK37AF11D67CB035

              
          drop table if exists husband

              
          drop table if exists wife

              
          create table husband (
                  id 
          integer not null auto_increment,
                  name 
          varchar(255),
                  
          primary key (id)
              )

              
          create table wife (
                  id 
          integer not null,
                  name 
          varchar(255),
                  
          primary key (id)
              )

              
          alter table wife 
                  
          add index FK37AF11D67CB035 (id), 
                  
          add constraint FK37AF11D67CB035 
                  
          foreign key (id) 
                  
          references husband (id)

          @Test
              
          public void insert(){
                  Session session
          =HibernateSessionFactory.getSession();
                  Transaction transaction
          =session.beginTransaction();
                  
          try {
                      transaction.begin();
                      Husband husband
          =new Husband();
                      husband.setName(
          "小明");
                      session.save(husband);
                      Wife wife
          =new Wife();
                      wife.setName(
          "如花");
                      wife.setHusband(husband);
                      wife.setId(husband.getId());
                      session.save(wife);
                      transaction.commit();
                  } 
          catch (HibernateException e) {
                      e.printStackTrace();
                      transaction.rollback();
                  }
              }
          @Test
              
          public void insert(){
                  Session session
          =HibernateSessionFactory.getSession();
                  Transaction transaction
          =session.beginTransaction();
                  
          try {
                      transaction.begin();
                      Husband husband
          =new Husband();
                      husband.setName(
          "小明");
                      session.save(husband);
                      Wife wife
          =new Wife();
                      wife.setName(
          "如花");
                      wife.setHusband(husband);
                      wife.setId(husband.getId());
                      session.save(wife);
                      transaction.commit();
                  } 
          catch (HibernateException e) {
                      e.printStackTrace();
                      transaction.rollback();
                  }
              }
          溫馨提醒:此處必須同時設(shè)置
          wife.setHusband(husband);
          wife.setId(husband.getId());
          否則報org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

          示例程序
          posted @ 2010-10-14 10:28 雪山飛鵠 閱讀(2240) | 評論 (1)編輯 收藏


          alter table wife
                  drop
                  foreign key FK37AF11D67CB035

              drop table if exists husband

              drop table if exists wife

              create table husband (
                  id integer not null auto_increment,
                  name varchar(255),
                  primary key (id)
              )

              create table wife (
                  id integer not null,
                  name varchar(255),
                  primary key (id)
              )

              alter table wife
                  add index FK37AF11D67CB035 (id),
                  add constraint FK37AF11D67CB035
                  foreign key (id)
                  references husband (id)

          實體
          Husband

          private int id;
           private String name;
           private Wife wife;

          Wife
          private int id;
           private String name;
           private Husband husband;

          Husband.hbm.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE hibernate-mapping PUBLIC 
              "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
              "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
          >
              
          <hibernate-mapping package="com.hibernate.one2one.bean">
                  
          <class name="Husband" table="husband">
                      
          <id name="id" column="id">
                          
          <generator class="native"></generator>
                      
          </id>
                      
          <property name="name"></property>
                      
          <one-to-one name="wife" cascade="all" class="Wife"></one-to-one>
                  
          </class>
              
          </hibernate-mapping>

          Wife.hbm.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE hibernate-mapping PUBLIC 
              "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
              "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
          >
              
          <hibernate-mapping package="com.hibernate.one2one.bean">
                  
          <class name="Wife" table="wife">
                      
          <id name="id" column="id">
                          
          <generator class="foreign">
                              
          <param name="property">husband</param>
                          
          </generator>
                      
          </id>
                      
          <property name="name"></property>
                      
          <one-to-one name="husband" constrained="true"></one-to-one>
                  
          </class>
              
          </hibernate-mapping>
          @Test
              
          public void insert(){
                  Session session
          =HibernateSessionFactory.getSession();
                  Transaction transaction
          =session.beginTransaction();
                  
          try {
                      transaction.begin();
                      Husband husband
          =new Husband();
                      husband.setName(
          "小明");
                      session.save(husband);
                      Wife wife
          =new Wife();
                      wife.setName(
          "如花");
                      wife.setHusband(husband);
                      session.save(wife);
                      transaction.commit();
                  } 
          catch (HibernateException e) {
                      e.printStackTrace();
                      transaction.rollback();
                  }
              }


          示例程序
          posted @ 2010-10-14 10:01 雪山飛鵠 閱讀(679) | 評論 (0)編輯 收藏


          create table Husband
          (
             id                   
          int not null auto_increment,
             name                 
          varchar(200),
             
          primary key (id)
          );
          create table Wife
          (
             id                   
          int not null,
             name                 
          varchar(20),
             
          primary key (id)
          );
          alter table Wife add constraint FK_Reference_1 foreign key (id)
                
          references Husband (id) on delete restrict on update restrict;
          Wife.java
          package com.jpa.one2one.bean;

          import java.io.Serializable;

          import javax.persistence.Column;
          import javax.persistence.Entity;
          import javax.persistence.Id;
          import javax.persistence.OneToOne;
          import javax.persistence.PrimaryKeyJoinColumn;
          import javax.persistence.Table;

          @SuppressWarnings(
          "serial")
          @Entity
          @Table
          public class Wife implements Serializable{
              
          private int id;
              
          private String name;
              
          private Husband husband;
              @Id
              @Column
              
          public int getId() {
                  
          return id;
              }
              
          public void setId(int id) {
                  
          this.id = id;
              }
              @Column(name
          ="name")
              
          public String getName() {
                  
          return name;
              }
              
          public void setName(String name) {
                  
          this.name = name;
              }
              @OneToOne
              @PrimaryKeyJoinColumn
              
          public Husband getHusband() {
                  
          return husband;
              }
              
          public void setHusband(Husband husband) {
                  
          this.husband = husband;
              }
              
          }
          Husband.java
          package com.jpa.one2one.bean;

          import javax.persistence.CascadeType;
          import javax.persistence.Column;
          import javax.persistence.Entity;
          import javax.persistence.GeneratedValue;
          import javax.persistence.GenerationType;
          import javax.persistence.Id;
          import javax.persistence.OneToOne;
          import javax.persistence.PrimaryKeyJoinColumn;
          import javax.persistence.Table;

          @Entity
          @Table
          public class Husband {
              
              
          private int id;
              
          private String name;
              
          private Wife wife;
              @Id
              @Column
              @GeneratedValue(strategy
          =GenerationType.AUTO)
              
          public int getId() {
                  
          return id;
              }
              
          public void setId(int id) {
                  
          this.id = id;
              }
              @Column(name
          ="name")
              
          public String getName() {
                  
          return name;
              }
              
          public void setName(String name) {
                  
          this.name = name;
              }
              @OneToOne(cascade
          =CascadeType.ALL)
              @PrimaryKeyJoinColumn
              
          public Wife getWife() {
                  
          return wife;
              }
              
          public void setWife(Wife wife) {
                  
          this.wife = wife;
              }
              
          }
          HusbandDAO
          package com.jpa.one2one.dao;

          import javax.persistence.EntityManager;
          import javax.persistence.EntityTransaction;

          import org.junit.Test;

          import com.jpa.one2one.bean.Husband;
          import com.jpa.one2one.bean.Wife;
          import com.jpa.one2one.util.JPAUtil;

          public class HusbandDAO {
              
              @Test
              
          public void insert(){
                  EntityManager entityManager
          =JPAUtil.getInstance();
                  EntityTransaction transaction
          =entityManager.getTransaction();
                  
          try {
                      transaction.begin();
                      Husband husband
          =new Husband();
                      husband.setName(
          "張三");
                      entityManager.persist(husband);
                      Wife wife
          =new Wife();
                      
          //wife.setHusband(husband);
                      wife.setName("如花");
                      wife.setId(husband.getId());
                      entityManager.persist(wife);
                      transaction.commit();
                  } 
          catch (Exception e) {
                      e.printStackTrace();
                      transaction.rollback();
                  }
              }
          }
          JPAUtil
          package com.jpa.one2one.util;

          import javax.persistence.EntityManager;
          import javax.persistence.EntityManagerFactory;
          import javax.persistence.Persistence;

          public class JPAUtil {
              
              
          private static EntityManager entityManager;
              
          public static EntityManager getInstance(){
                  
          if(entityManager!=null){
                      
          return entityManager;
                  }
          else{
                      
          return makeInstance();
                  }
              }
              
          private static synchronized EntityManager makeInstance() {
                  
          if(entityManager==null){
                      EntityManagerFactory entityManagerFactory
          =Persistence.createEntityManagerFactory("JPAPU");
                      
          return entityManagerFactory.createEntityManager();
                  }
                  
          return null;
              }
          }
          persistence.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <persistence xmlns="http://java.sun.com/xml/ns/persistence"
              xmlns:xsi
          ="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation
          ="http://java.sun.com/xml/ns/persistence
              http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
           version="1.0">
              
              
          <persistence-unit name="JPAPU" transaction-type="RESOURCE_LOCAL">
                  
          <provider>org.hibernate.ejb.HibernatePersistence</provider>
                  
          <class>com.jpa.one2one.bean.Wife</class>
                  
          <class>com.jpa.one2one.bean.Husband</class>
                    
          <properties>
                      
          <property name = "hibernate.connection.driver_class" value = "com.mysql.jdbc.Driver"/>
                      
          <property name = "hibernate.connection.url" value = "jdbc:mysql://localhost:3306/JPA"/>
                      
          <property name = "hibernate.connection.username" value = "root"/>
                      
          <property name = "hibernate.connection.password" value = "root"/>
                      
          <property name="hibernate.show_sql" value="true"/>
                      
          <property name="hibernate.format_sql" value="true"/>
                    
          </properties>
              
          </persistence-unit>
            
          </persistence>

          示例程序
          posted @ 2010-10-14 09:23 雪山飛鵠 閱讀(3687) | 評論 (0)編輯 收藏

               摘要: 環(huán)境:         ibatis-2.3.4.726         使用ibatis2最小jar包配置         commons-collec...  閱讀全文
          posted @ 2010-10-13 12:06 雪山飛鵠 閱讀(2762) | 評論 (1)編輯 收藏

          Spring不但支持自己定義的@Autowired注解,還支持幾個由JSR-250規(guī)范定義的注解,它們分別是@Resource、@PostConstruct以及@PreDestroy。
            @Resource的作用相當于@Autowired,只不過@Autowired按byType自動注入,而@Resource默認按 byName自動注入罷了。@Resource有兩個屬性是比較重要的,分是name和type,Spring將@Resource注解的name屬性解析為bean的名字,而type屬性則解析為bean的類型。所以如果使用name屬性,則使用byName的自動注入策略,而使用type屬性時則使用byType自動注入策略。如果既不指定name也不指定type屬性,這時將通過反射機制使用byName自動注入策略。
            @Resource裝配順序
            1. 如果同時指定了name和type,則從Spring上下文中找到唯一匹配的bean進行裝配,找不到則拋出異常
            2. 如果指定了name,則從上下文中查找名稱(id)匹配的bean進行裝配,找不到則拋出異常
            3. 如果指定了type,則從上下文中找到類型匹配的唯一bean進行裝配,找不到或者找到多個,都會拋出異常
            4. 如果既沒有指定name,又沒有指定type,則自動按照byName方式進行裝配;如果沒有匹配,則回退為一個原始類型進行匹配,如果匹配則自動裝配;
          posted @ 2010-10-11 16:52 雪山飛鵠 閱讀(45116) | 評論 (6)編輯 收藏

          According to TLD or attribute directive in tag file, attribute test does not accept any expressions

          2.4及以后寫成(JSTL1.1) 
          <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 

          2.3及以前(JSTL1.0)
          <%@taglib prefix="c" uri="http://java.sun.com/jstl/core" %> 
          posted @ 2010-10-10 15:07 雪山飛鵠 閱讀(235) | 評論 (0)編輯 收藏

          java.lang.NoSuchMethodError: javax.persistence.OneToOne.orphanRemoval()Z
          ejb3的jar包與JPA包沖突 ejb3的jar包刪除就OK了

          java.lang.NoClassDefFoundError: javax/persistence/Cacheable
          錯誤原因,javax.persistence.Cacheable 是 JPA 2.0 規(guī)范中的東西!
          支持 JPA 2 的 Hibernate 實現(xiàn) 3.5 版目前還處于CR2 版本之中,還沒有正式發(fā)布。
          需要在加入hibernate-distribution-3.5.0-Final\lib\jpa目錄下的hibernate-jpa-2.0-api-1.0.0.Final.jar

          java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
          缺少slf4j-nop-1.5.8.jar
          posted @ 2010-10-09 10:42 雪山飛鵠 閱讀(1649) | 評論 (1)編輯 收藏

               摘要:   使用Xdoclet和Ant構(gòu)建Hibernate映射和配置文件 溫馨提示:由于文檔中含大量圖片,這里不方便一一上傳建議下載本文電子版文檔閱讀 Xdoclet.pdf 本文工程下載 svn地址:http://xdocletdemo.googlecode.com/svn/trunk/ 功能描述:       &...  閱讀全文
          posted @ 2010-09-30 16:03 雪山飛鵠 閱讀(2981) | 評論 (3)編輯 收藏

          1. PHP

          PHP Cheat Sheet

          http://www.addedbytes.com/cheat-sheets/php-cheat-sheet/

          2. MySQL

          MySQL Cheat Sheet

          http://www.addedbytes.com/cheat-sheets/mysql-cheat-sheet/

          3. JavaScript

          JavaScript Cheat Sheet

          http://www.addedbytes.com/cheat-sheets/javascript-cheat-sheet/

          4. CSS

          CSS Cheat Sheet

          http://www.addedbytes.com/cheat-sheets/css-cheat-sheet/

          5. Regular Expressions

           

          Regular Expressions Cheat Sheet

          http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/

          6. Apache’s mod_rewrite

          mod_rewrite Cheat Sheet

          http://www.addedbytes.com/apache/mod_rewrite-cheat-sheet/

          7. jQuery

          jQuery Cheat Sheet

          http://acodingfool.typepad.com/blog/pdf/jquery_1.3_cheatsheet_v1.pdf

          8. HTML

          HTML Cheat Sheet

          http://www.addedbytes.com/cheat-sheets/html-cheat-sheet/

          9. HTML Character Entities

          HTML Entities Cheat Sheet

          http://www.addedbytes.com/cheat-sheets/html-character-entities-cheat-sheet/

          10. RGB Hex Color Codes

          RGB Color Codes Cheat Sheet

          http://www.addedbytes.com/cheat-sheets/colour-chart/

          11. .htaccess

          .htaccess Cheat Sheet

          http://www.thejackol.com/htaccess-cheatsheet/

          12. Apache

          Apache Cheat Sheet

          http://www.petefreitag.com/cheatsheets/apache/

          13. SEO

          SEO Cheat Sheet

          http://www.seomoz.org/blog/the-web-developers-seo-cheat-sheet

          14. Gmail

          Gmail Cheat Sheet

          http://www.marcofolio.net/cheat_sheets/gmail_keyboard_shortcuts_cheat_sheet.html

          15. HTML5

          HTML5 Cheat Sheet

          http://www.smashingmagazine.com/2009/07/06/html-5-cheat-sheet-pdf/

          16. Google Analytics

          Google Analytics Cheat Sheet

          http://www.searchenginejournal.com/the-huge-collection-of-google-analytics-tips/7426/

          17. WordPress Cheat Sheets

          WordPress Cheat Sheets

          http://speckyboy.com/2009/06/17/14-essential-wordpress-development-and-design-cheat-sheets/

          18. Subversion

          Subversion Cheat Sheet

          http://www.addedbytes.com/cheat-sheets/subversion-cheat-sheet/

          19. Eclipse

          Eclipse Cheat Sheet

          http://refcardz.dzone.com/refcardz/getting-started-eclipse?oid=hom7187

          20. Google Search Engine

          Google Cheat Sheet

          http://www.google.com/help/cheatsheet.html

          21. Twitter

          Twitter Cheat Sheet

          http://jasontheodor.com/2009/04/28/twitter-tweet-sheet-2/

          22. CakePHP

          CakePHP Cheat Sheet

          http://cakephp.org/files/Resources/CakePHP-1.2-Cheatsheet.pdf

          23. Joomla

          Joomla 1.5 Cheat Sheet

          http://www.younic.de/joomla-basic-template-cheatsheet

          24. CodeIgniter

          CodeIgniter Cheat Sheet

          http://designfellow.com/blog/freebies/codeigniter-quick-reference-cheat-sheet-version-2-0-released/

          25. Drupal

          Drupal Cheat Sheet

          http://www.inmensia.com/files/pictures/internal/CheatSheetDrupal4.7.png

          26. Firebug

          Firebug Cheat Sheet

          http://duvet-dayz.com/firebug-cheatsheet/

          posted @ 2010-09-29 17:18 雪山飛鵠 閱讀(1104) | 評論 (1)編輯 收藏

          僅列出標題
          共22頁: First 上一頁 8 9 10 11 12 13 14 15 16 下一頁 Last 
          主站蜘蛛池模板: 梁山县| 鄂尔多斯市| 光山县| 中山市| 嘉善县| 吴江市| 蓝山县| 方城县| 普格县| 商城县| 秀山| 儋州市| 平邑县| 张北县| 玉林市| 泰来县| 砚山县| 上虞市| 蕲春县| 沂水县| 开封市| 贵溪市| 德格县| 广汉市| 福泉市| 奇台县| 正镶白旗| 长沙市| 嘉荫县| 肇庆市| 武隆县| 广河县| 庄浪县| 班玛县| 旺苍县| 图们市| 南皮县| 阿克| 岳池县| 肥乡县| 林芝县|