成功捷徑,貴在堅持
          人為善,福雖未至禍已遠(yuǎn)離; 人為惡,禍雖未至福已遠(yuǎn)離
          簡體繁體轉(zhuǎn)換
          posted @ 2008-06-19 12:01 選寶網(wǎng)an9 閱讀(801) | 評論 (1)編輯 收藏
          eclipse struts2插件下載
          posted @ 2008-05-30 15:18 選寶網(wǎng)an9 閱讀(8577) | 評論 (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 選寶網(wǎng)an9 閱讀(4475) | 評論 (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、去掉藍(lán)色注釋的部分即可解決錯誤.
          2、?注:@ManyToMany(mappedBy="authors",屬性一定要和book中的authors一致。

          posted @ 2008-05-20 08:54 選寶網(wǎng)an9 閱讀(6682) | 評論 (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做為連接池測試的應(yīng)用程序,注釋的部分去掉即可解決Exception.
          posted @ 2008-05-19 14:51 選寶網(wǎng)an9 閱讀(2998) | 評論 (0)編輯 收藏
          google詞霸翻譯
          posted @ 2008-05-08 16:33 選寶網(wǎng)an9 閱讀(339) | 評論 (1)編輯 收藏
          java代碼規(guī)范
          posted @ 2008-05-05 18:24 選寶網(wǎng)an9 閱讀(324) | 評論 (0)編輯 收藏
          jsp編程指南2nd代碼下載
          posted @ 2008-05-05 17:45 選寶網(wǎng)an9 閱讀(273) | 評論 (0)編輯 收藏
          上海地鐵時刻表
          posted @ 2008-04-28 13:30 選寶網(wǎng)an9 閱讀(2161) | 評論 (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 選寶網(wǎng)an9 閱讀(2752) | 評論 (0)編輯 收藏
          僅列出標(biāo)題
          共8頁: 上一頁 1 2 3 4 5 6 7 8 下一頁 
          主站蜘蛛池模板: 边坝县| 辽阳县| 宁津县| 吉木萨尔县| 榕江县| 安徽省| 定日县| 东宁县| 名山县| 玛沁县| 奎屯市| 临猗县| 博爱县| 桐城市| 鸡东县| 黄骅市| 翁牛特旗| 濮阳县| 安达市| 湾仔区| 潮州市| 翁源县| 望江县| 竹北市| 仙桃市| 塔河县| 岚皋县| 海林市| 贵港市| 大名县| 宜城市| 玉树县| 鹤岗市| 邵东县| 手游| 江山市| 平舆县| 宝丰县| 宁陵县| 阳春市| 比如县|