ï»??xml version="1.0" encoding="utf-8" standalone="yes"?>国产激情综合,亚洲国产精品美女,亚洲精品国精品久久99热http://www.aygfsteel.com/honzeland/category/43478.html记录ç‚ÒŽ(gu¨©)»´ã€‚。ã€?/description>zh-cnSat, 09 Oct 2010 05:20:35 GMTSat, 09 Oct 2010 05:20:35 GMT60GWT 2 Spring 3 JPA 2 Hibernate 3.5 Tutorial â€?Eclipse and Maven 2 showcase http://www.aygfsteel.com/honzeland/archive/2010/08/20/329452.htmlhonzelandhonzelandFri, 20 Aug 2010 05:01:00 GMThttp://www.aygfsteel.com/honzeland/archive/2010/08/20/329452.htmlhttp://www.aygfsteel.com/honzeland/comments/329452.htmlhttp://www.aygfsteel.com/honzeland/archive/2010/08/20/329452.html#Feedback0http://www.aygfsteel.com/honzeland/comments/commentRss/329452.htmlhttp://www.aygfsteel.com/honzeland/services/trackbacks/329452.htmlhttp://www.javacodegeeks.com/2010/07/gwt-2-spring-3-jpa-2-hibernate-35.html

]]>
Hibernate Annotationshttp://www.aygfsteel.com/honzeland/archive/2010/04/20/318875.htmlhonzelandhonzelandTue, 20 Apr 2010 09:20:00 GMThttp://www.aygfsteel.com/honzeland/archive/2010/04/20/318875.htmlhttp://www.aygfsteel.com/honzeland/comments/318875.htmlhttp://www.aygfsteel.com/honzeland/archive/2010/04/20/318875.html#Feedback0http://www.aygfsteel.com/honzeland/comments/commentRss/318875.htmlhttp://www.aygfsteel.com/honzeland/services/trackbacks/318875.htmlUse one single table "blank_fields" for both A and B. "blank_fields" has fields: 'ref_id', 'blank_field', 'type'. 'type' is used to identify which entity the record belongs to. Use 'type' + 'ref_id' to specify the collection of elements for one entity.

@Entity
@Table(name 
= "table_a")
public class A {
    
private Set<BlankField> blankFields = new HashSet<BlankField>();
   
    @CollectionOfElements
    @Fetch(FetchMode.SUBSELECT)
    @Enumerated(EnumType.ORDINAL)
    @JoinTable(name 
= "blank_fields", joinColumns = { @JoinColumn(name = "ref_id") })
    @Cascade(value 
= org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    @Column(name 
= "blank_field", nullable = false)
    @SQLInsert(sql 
= "INSERT INTO blank_fields(ref_id, blank_field, type) VALUES(?,?,0)")
    @Where(clause 
= "type=0")
    
public Set<BlankField> getBlankFields() { // BlankField is an enum
        
return blankFields;
    }

    @SuppressWarnings(
"unused")
    
private void setBlankFields(Set<BlankField> blankFields) {
        
this.blankFields = blankFields;
    }
// End B

@Entity
@Table(name 
= "table_b")
public class B {
    
private Set<BlankField> blankFields = new HashSet<BlankField>();
   
    @CollectionOfElements
    @Fetch(FetchMode.SUBSELECT)
    @Enumerated(EnumType.ORDINAL)
    @JoinTable(name 
= "blank_fields", joinColumns = { @JoinColumn(name = "ref_id") })
    @Cascade(value 
= org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    @Column(name 
= "blank_field", nullable = false)
    @SQLInsert(sql 
= "INSERT INTO blank_fields(ref_id, blank_field, type) VALUES(?,?,1)"// used for insert
    @Where(clause = "type=1"// used for query, if not @CollectionOfElements, such as @OneToMany, use @WhereJoinTable instead
    public Set<BlankField> getBlankFields() {
        
return blankFields;
    }

    @SuppressWarnings(
"unused")
    
private void setBlankFields(Set<BlankField> blankFields) {
        
this.blankFields = blankFields;
    }
}

当然˜q˜æœ‰å…¶ä»–的方式来实现上面的需求,上面采用的单表来记录不同实体的associationsåQˆè¿™å„¿æ˜¯CollectionOfElementsåQŒåƈ且返回的是Set<Enum>åQŒä¸æ˜¯Set<Embeddable>)åQŒç„¶åŽç”¨'type'来区分不同的实体åQŒè¿™æ ·åšçš„好处是åQšæ•°æ®åº“å†—ä½™ž®‘,易于扩展åQŒå¯¹äºŽæ–°çš„实体,只需加一个typeå€û|¼Œè€Œä¸éœ€æ›´æ”¹æ•°æ®åº“表¾l“构。另外一¿Ué‡‡ç”¨å•è¡¨çš„æ–¹å¼æ˜¯äØ“(f¨´)每个实体增加新的字段åQŒå¦‚
"blank_fields": 'a_id', 'b_id', 'blank_field', a_id reference table_a (id), b_id reference table_b (id). ˜q™æ ·åœ¨æ˜ ž®„的时候更½Ž€å•,
对于AåQŒæ˜ ž®„䨓(f¨´)
@JoinTable(name = "blank_fields", joinColumns = { @JoinColumn(name = "a_id") })
对于BåQŒæ˜ ž®„䨓(f¨´)
@JoinTable(name = "blank_fields", joinColumns = { @JoinColumn(name = "b_id") })
˜q™æ ·ä½œçš„¾~ºç‚¹æ˜¯ï¼š(x¨¬)带来了数据库冗余åQŒå¯¹äº?span style="color: #000000;">blank_fields来讲åQŒä“Q一条记录,a_idå’Œb_id中只有一个不为null。当多个实体å…Þq”¨˜q™ä¸ªè¡¨æ—¶åQŒç”¨ä¸Šé¢çš„æ–¹æ³•更合理åQŒå¦‚果共用实体不多时åQŒè¿™¿Uæ–¹æ³•更方便ã€?/span>

]]>
One Hibernate Session Multiple Transactionshttp://www.aygfsteel.com/honzeland/archive/2010/03/01/314150.htmlhonzelandhonzelandMon, 01 Mar 2010 03:47:00 GMThttp://www.aygfsteel.com/honzeland/archive/2010/03/01/314150.htmlhttp://www.aygfsteel.com/honzeland/comments/314150.htmlhttp://www.aygfsteel.com/honzeland/archive/2010/03/01/314150.html#Feedback0http://www.aygfsteel.com/honzeland/comments/commentRss/314150.htmlhttp://www.aygfsteel.com/honzeland/services/trackbacks/314150.html each transaction would NOT affect others.
i.e., open multiple transactions on the same session, even though one transaction rolls back, other transactions can be committed. If one action fails, others should fail too, then we should use one transaction for all actions.

Note:
A rollback with a single Session will lead to that Session being cleared (through "Session.clear()").
So do lazy collections still work if the session is cleared? =>Not of any objects that you loaded up until the rollback. Only for new objects loaded afterwards.
We should load necessary objects to session for each transactional action to avoid LazyInitializationException, even if those objects are loaded before other forward transactional actions, since forward action may be rolled back and clear the session.

BTW, Hibernate Session.merge() is different with Session.update() by:
Item item2 = session.merge(item);
item2 
== item; // false, item - DETACHED, item2 - PERSIST
session.update(item); // no return value, make item PERSIST




]]>
org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has been marked as rollback-onlyhttp://www.aygfsteel.com/honzeland/archive/2010/02/24/313829.htmlhonzelandhonzelandWed, 24 Feb 2010 10:02:00 GMThttp://www.aygfsteel.com/honzeland/archive/2010/02/24/313829.htmlhttp://www.aygfsteel.com/honzeland/comments/313829.htmlhttp://www.aygfsteel.com/honzeland/archive/2010/02/24/313829.html#Feedback0http://www.aygfsteel.com/honzeland/comments/commentRss/313829.htmlhttp://www.aygfsteel.com/honzeland/services/trackbacks/313829.html
    @Transactional
    
public void foo() {
        
try{
            bar();
        } 
catch (RuntimeException re) {
            
// caught but not throw further
            
        }
        
    }

    @Transactional
    
public void bar() {
        
    }
如果foo在调用bar的时候,bar抛出RuntimeExceptionåQŒSpring在bar returnæ—¶å°†Transactional标记为Rollback onlyåQ?而foo捕获了barçš„RuntimeExceptionåQŒæ‰€ä»¥Springž®†ä¼š(x¨¬)commit foo的事务,但是fooå’Œbar使用的是同一事务åQŒå› æ­¤åœ¨commit foo事务æ—Óž¼Œž®†ä¼š(x¨¬)抛出UnexpectedRollbackException。注意:(x¨¬)如果fooå’Œbar在同一class中,不会(x¨¬)出现˜q™ç§æƒ…况åQŒå› ä¸ºï¼š(x¨¬)

Since this mechanism is based on proxies, only 'external' method calls coming in through the proxy will be intercepted. This means that 'self-invocation', i.e. a method within the target object calling some other method of the target object, won't lead to an actual transaction at runtime even if the invoked method is marked with @Transactional!

可以通过配置log4j来debug Spring事务获取情况åQ?br /> To delve more into it I would turn up your log4j logging to debug and also look at what ExerciseModuleController is doing at line 91, e.g.: add a logger for org.springframework.transaction


]]>
Discussion for Open Session In View Pattern for Hibernatehttp://www.aygfsteel.com/honzeland/archive/2010/01/29/311244.htmlhonzelandhonzelandFri, 29 Jan 2010 09:20:00 GMThttp://www.aygfsteel.com/honzeland/archive/2010/01/29/311244.htmlhttp://www.aygfsteel.com/honzeland/comments/311244.htmlhttp://www.aygfsteel.com/honzeland/archive/2010/01/29/311244.html#Feedback0http://www.aygfsteel.com/honzeland/comments/commentRss/311244.htmlhttp://www.aygfsteel.com/honzeland/services/trackbacks/311244.htmlhttp://www.mail-archive.com/stripes-users@lists.sourceforge.net/msg02908.html




]]>
Ö÷Õ¾Ö©Öë³ØÄ£°å£º ½«ÀÖÏØ| ²Æ¾­| ÄÏͶÊÐ| ãÏÖÐÊÐ| äàË®ÏØ| ·½ÕýÏØ| äü¹ØÏØ| ±£Í¤| Æ½ÒØÏØ| ´ëÃÀÏØ| Ì«ÆÍËÂÆì| ÂÞ¶¨ÊÐ| ÄÒÇ«ÏØ| »³ÈáÇø| ²©ÀÖÊÐ| Î÷¼ªÏØ| ¶þÊÖ·¿| ÂÀÁºÊÐ| ÌìÆø| ÀÖ²ýÊÐ| Æ½Ô­ÏØ| ¸¡É½ÏØ| ½­ÓÍÊÐ| ¿ª»¯ÏØ| ½­´ïÏØ| Îâ½­ÊÐ| ¸ÊËàÊ¡| »¯ÖÝÊÐ| ÄÏÁêÏØ| ÐÂÐËÏØ| ÎÚÀ¼ÏØ| Îâ½­ÊÐ| »´ÑôÏØ| ÆÁ¶«ÊÐ| ÌÒ½­ÏØ| ºé½­ÊÐ| ÃñºÍ| ÅìºþÏØ| ÑÓ´¨ÏØ| ºÍ¾²ÏØ| ɳºÓÊÐ|