成功捷径,贵在坚持
人为善,福虽未至祸已远离; 人为恶,祸虽未至福已远离
简体繁体转换
posted @ 2008-06-19 12:01 选宝网an9 阅读(796) | 评论 (1)编辑 收藏
eclipse struts2插件下载
posted @ 2008-05-30 15:18 选宝网an9 阅读(8558) | 评论 (3)编辑 收藏
     摘要: package  com.e104cn.pda.data.anno; import  java.io.Serializable; import  java.util.Date; import  javax.persistence.CascadeType; import  javax.persistence.E...  阅读全文
posted @ 2008-05-21 08:19 选宝网an9 阅读(4458) | 评论 (0)编辑 收藏

@SuppressWarnings("serial")
@Entity
@Table(name = "BOOK")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Book implements Serializable{

 private static final long serialVersionUID = -2700610405985954588L;
 
 private int oid;
 
 private String name;
 
 private String description;
 
 private Date publish;
 
 private Collection<Author> authors;

 @Id
 @GeneratedValue(strategy=GenerationType.SEQUENCE)
 public int getOid() {
  return oid;
 }

 public void setOid(int oid) {
  this.oid = oid;
 }

 public String getName() {
  return name;
 }

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

 public String getDescription() {
  return description;
 }

 public void setDescription(String description) {
  this.description = description;
 }

 @Temporal(value=TemporalType.TIMESTAMP)
 public Date getPublish() {
  return publish;
 }

 public void setPublish(Date publish) {
  this.publish = publish;
 }


 @ManyToMany(
   targetEntity=com.e104cn.pda.data.anno.Author.class,
   cascade ={CascadeType.PERSIST,CascadeType.MERGE},
            fetch=FetchType.LAZY
 )
 @JoinTable(
         name = "book_author",
         joinColumns ={@JoinColumn(name="book_id")},
         inverseJoinColumns ={@JoinColumn(name= "author_id")}
   )
 public Collection<Author> getAuthors() {
  return authors;
 }
 
 public void addAuthor(Author author){
  if(author == null){
   authors = new ArrayList<Author>();
  }
  if(!authors.contains(author)){
   authors.add(author);
  }
 }

 public void setAuthors(Collection<Author> authors) {
  this.authors = authors;
 }
 
}

/**@SuppressWarnings("serial")
@Entity
@Table(name = "AUTHOR")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)*/

public class Author implements Serializable{

 private static final long serialVersionUID = 7131973910486229579L;
 
 private int id;
 
 private String firstName;
 
 private String lastName;
 
 private boolean male;
 
 private Date birthday;
 
 @Transient
 private Collection<Book> books ;

 @Id
 @GeneratedValue(strategy=GenerationType.SEQUENCE)
 public int getId() {
  return id;
 }

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

 public String getFirstName() {
  return firstName;
 }

 public void setFirstName(String firstName) {
  this.firstName = firstName;
 }

 public String getLastName() {
  return lastName;
 }

 public void setLastName(String lastName) {
  this.lastName = lastName;
 }

 public boolean isMale() {
  return male;
 }

 public void setMale(boolean male) {
  this.male = male;
 }

 @Temporal(value=TemporalType.TIMESTAMP)
 public Date getBirthday() {
  return birthday;
 }

 public void setBirthday(Date birthday) {
  this.birthday = birthday;
 }

 @ManyToMany(mappedBy="authors",
  cascade={CascadeType.PERSIST,CascadeType.ALL}
 )
 public Collection<Book> getBooks() {
  return books;
 }

 public void addBook(Book book){
  if(books == null){
   books = new ArrayList<Book>();
  }
  if(!books.contains(book)){
   books.add(book);
  }
 }
 
 public void setBooks(Collection<Book> books) {
  this.books = books;
 }
 
}
1、去掉蓝色注释的部分即可解决错误.
2、 注:@ManyToMany(mappedBy="authors",属性一定要和book中的authors一致。

posted @ 2008-05-20 08:54 选宝网an9 阅读(6667) | 评论 (0)编辑 收藏
 1 package  com.e104cn.pda.test;
 2 import  org.junit.AfterClass;
 3 import  org.junit.BeforeClass;
 4 import  org.junit.Test;
 5 import  org.logicalcobwebs.proxool.ProxoolFacade;
 6 import  org.springframework.context.ApplicationContext;
 7 import  org.springframework.context.support.FileSystemXmlApplicationContext;
 8
 9 import  tw.com.testing.util.Code;
10
11 import  com.e104cn.pda.data.anno.Basic;
12 import  com.e104cn.pda.data.dao.IBasicDao;
13 public   class  BasicDAOTest {
14      private   static  ApplicationContext context;
15     @BeforeClass
16      public   static   void  setUp() {
17         context  =   new  FileSystemXmlApplicationContext( new  String[] { " WebContent/WEB-INF/applicationContext-hibernate.xml " , " WebContent/WEB-INF/applicationContext-service.xml " , " WebContent/WEB-INF/applicationContext-dao.xml " } );
18     }

19     
20     @AfterClass
21      public   static   void  tearDown() {
22          // ProxoolFacade.shutdown(0); 
23     }

24     
25     @Test
26      public   void  contextInit() {
27          if (context  !=   null ) {
28             IBasicDao basicDao  =  (IBasicDao)context.getBean( " basicDao " );
29              if (basicDao  !=   null ) {
30                  try   {
31                     Basic basic  =  (Basic)basicDao.getData( " 105400 " );
32                      if (basic  !=   null ) {
33                         System.out.println( new  Code().decode(basic.getEmail()));
34                     }

35                 }
  catch  (Exception e)  {
36                     e.printStackTrace();
37                 }

38             }

39         }

40     }

41 }

42
spring2.0,hibernate annotation,juint4, proxool做为连接池测试的应用程序,注释的部分去掉即可解决Exception.
posted @ 2008-05-19 14:51 选宝网an9 阅读(2977) | 评论 (0)编辑 收藏
google词霸翻译
posted @ 2008-05-08 16:33 选宝网an9 阅读(325) | 评论 (1)编辑 收藏
java代码规范
posted @ 2008-05-05 18:24 选宝网an9 阅读(314) | 评论 (0)编辑 收藏
jsp编程指南2nd代码下载
posted @ 2008-05-05 17:45 选宝网an9 阅读(262) | 评论 (0)编辑 收藏
上海地铁时刻表
posted @ 2008-04-28 13:30 选宝网an9 阅读(2150) | 评论 (2)编辑 收藏
struts2,hibernate3,mysql修改时报错
        Session session = HibernateUtil.getCurrentSessionFactory().openSession();
        Transaction transaction = null;
        try {
                transaction = session.beginTransaction();
                session.merge(user);        // 本来使用 saveOrupdate() 但是报错
                transaction.commit();          
         } catch (Exception e) {
            if (transaction != null) {
                transaction.rollback();
            }
            throw e;
         } finally {
            if (session != null) {
                session.close();
            }
         }
          
posted @ 2008-04-18 16:13 选宝网an9 阅读(2739) | 评论 (0)编辑 收藏
仅列出标题
共8页: 上一页 1 2 3 4 5 6 7 8 下一页