簡體繁體轉換
posted @
2008-06-19 12:01 選寶網an9 閱讀(799) |
評論 (1) |
編輯 收藏
eclipse struts2插件下載
posted @
2008-05-30 15:18 選寶網an9 閱讀(8570) |
評論 (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 閱讀(4467) |
評論 (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 閱讀(6672) |
評論 (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 閱讀(2993) |
評論 (0) |
編輯 收藏
google詞霸翻譯
posted @
2008-05-08 16:33 選寶網an9 閱讀(332) |
評論 (1) |
編輯 收藏
java代碼規范
posted @
2008-05-05 18:24 選寶網an9 閱讀(320) |
評論 (0) |
編輯 收藏
jsp編程指南2nd代碼下載
posted @
2008-05-05 17:45 選寶網an9 閱讀(268) |
評論 (0) |
編輯 收藏
上海地鐵時刻表
posted @
2008-04-28 13:30 選寶網an9 閱讀(2154) |
評論 (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 閱讀(2745) |
評論 (0) |
編輯 收藏