锘??xml version="1.0" encoding="utf-8" standalone="yes"?>mm1313亚洲国产精品无码试看,亚洲精品一卡2卡3卡四卡乱码,久久精品亚洲日本佐佐木明希http://m.tkk7.com/andyj2ee/category/1035.htmljava tec skyzh-cnWed, 28 Feb 2007 04:06:35 GMTWed, 28 Feb 2007 04:06:35 GMT60Oracle Blob/Clob 瀛楁鍐欏叆鏃朵駭鐢熻漿鍨嬪紓甯窩ast Exceptionhttp://m.tkk7.com/andyj2ee/archive/2006/02/14/30633.htmljava鍏夌幆java鍏夌幆Tue, 14 Feb 2006 08:35:00 GMThttp://m.tkk7.com/andyj2ee/archive/2006/02/14/30633.htmlhttp://m.tkk7.com/andyj2ee/comments/30633.htmlhttp://m.tkk7.com/andyj2ee/archive/2006/02/14/30633.html#Feedback0http://m.tkk7.com/andyj2ee/comments/commentRss/30633.htmlhttp://m.tkk7.com/andyj2ee/services/trackbacks/30633.htmlCLOB clob = (CLOB)us.getStatisticsInfo();

鍘熷洜鏄?BR>java.sql.Blob涓嶈兘寮哄埗浼犲敜鎴恛racle.sql.BLOB

瑙e喅鏂規硶濡備笅錛?BR>
SerializableClob lob=(SerializableClob)us.getStatisticsInfo();
CLOB lob2 = (CLOB)lob.getWrappedClob(); 
Writer out = lob2.getCharacterOutputStream(); 
  

public void testAdd() throws Exception {
        
byte[] buffer = new byte[1]; 
        buffer[
0= 1;
        Session s 
= null;
        
try 
            s 
= sf.openSession(); 
            Transaction tx 
= s.beginTransaction();
            BizUserStatistics us
= new BizUserStatistics();
            us.setId(
new Long(100));
            us.setStatisticsInfo(Hibernate.createClob(
" "));

            s.save(us); 
            s.flush(); 
            s.refresh(us, LockMode.UPGRADE); 
//            CLOB clob = (CLOB)us.getStatisticsInfo(); 
            SerializableClob lob=(SerializableClob)us.getStatisticsInfo();
            CLOB lob2 
= (CLOB)lob.getWrappedClob();     
            Writer out 
= lob2.getCharacterOutputStream();
            String fileName 
= "d:/process_log.sql";
            File f 
= new File(fileName); 
            FileInputStream fin 
= new FileInputStream(f);
 
            StringBuffer sb 
= new StringBuffer();
            
for (int i = 0; i < 1000; i++){
                sb.append(
"<data>" + i + "</data>");
            }

            out.write(sb.toString());
            out.close();
            
            s.flush(); 
            tx.commit(); 
            }
 catch (Exception e) {
                e.printStackTrace(); 
            }
 finally {
                
if (s != null)
                
try {
                s.close(); 
                }
 catch (Exception e){}
            }


    }



java鍏夌幆 2006-02-14 16:35 鍙戣〃璇勮
]]>
WARN afterTransactionCompletion() was never calledhttp://m.tkk7.com/andyj2ee/archive/2005/10/08/14968.htmljava鍏夌幆java鍏夌幆Sat, 08 Oct 2005 01:58:00 GMThttp://m.tkk7.com/andyj2ee/archive/2005/10/08/14968.htmlhttp://m.tkk7.com/andyj2ee/comments/14968.htmlhttp://m.tkk7.com/andyj2ee/archive/2005/10/08/14968.html#Feedback2http://m.tkk7.com/andyj2ee/comments/commentRss/14968.htmlhttp://m.tkk7.com/andyj2ee/services/trackbacks/14968.htmlafterTransactionCompletion() was never called
unclosed connection, forgot to call close() on your session?


璀﹀憡: afterTransactionCompletion() was never called

鎵ц浜唗x = session.beginTransaction();

浣嗘槸鍚庢潵娌″鐞唗x

搴旇鐢╰x.commit() or tx.rollback()

涓鑸煡璇㈡椂瀹規槗鍑虹幇姝ら棶棰?/P>

java鍏夌幆 2005-10-08 09:58 鍙戣〃璇勮
]]>
hibernate ant Hbm2JavaTask Exception of:org.xml.sax.SAXParseException: Attribute "insert" must be declared for element type "discriminator".http://m.tkk7.com/andyj2ee/archive/2005/08/19/10504.htmljava鍏夌幆java鍏夌幆Fri, 19 Aug 2005 05:52:00 GMThttp://m.tkk7.com/andyj2ee/archive/2005/08/19/10504.htmlhttp://m.tkk7.com/andyj2ee/comments/10504.htmlhttp://m.tkk7.com/andyj2ee/archive/2005/08/19/10504.html#Feedback0http://m.tkk7.com/andyj2ee/comments/commentRss/10504.htmlhttp://m.tkk7.com/andyj2ee/services/trackbacks/10504.html<discriminator type="java.lang.String" column="REGION_TYPE"
   length="10" force="false" insert="true"/>

Region.hbm.xml(15)
org.xml.sax.SAXParseException: Attribute "insert" must be declared for element type "discriminator".

        at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
        at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
        at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
        at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
        at org.apache.xerces.impl.dtd.XMLDTDValidator.addDTDDefaultAttrsAndValidate(Unknown Source)
        at org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
        at org.apache.xerces.impl.dtd.XMLDTDValidator.emptyElement(Unknown Source)
        at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(
Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at org.jdom.input.SAXBuilder.build(Unknown Source)
        at org.jdom.input.SAXBuilder.build(Unknown Source)
        at org.jdom.input.SAXBuilder.build(Unknown Source)
        at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:100)
        at net.sf.hibernate.tool.hbm2java.Hbm2JavaTask.processFile(Hbm2JavaTask.java:149)
        at net.sf.hibernate.tool.hbm2java.Hbm2JavaTask.execute(Hbm2JavaTask.java:97)
        at org.apache.tools.ant.Task.perform(Task.java:341)
        at org.apache.commons.jelly.tags.ant.AntTag.doTag(AntTag.java:185)
        at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:233)
        at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:89)
        at org.apache.maven.jelly.tags.werkz.MavenGoalTag.runBodyTag(MavenGoalTag.java:79)
        at org.apache.maven.jelly.tags.werkz.MavenGoalTag$MavenGoalAction.performAction(MavenGoalTag
.java:110)
        at com.werken.werkz.Goal.fire(Goal.java:639)
        at com.werken.werkz.Goal.attain(Goal.java:575)
        at com.werken.werkz.Goal.attainPrecursors(Goal.java:488)
        at com.werken.werkz.Goal.attain(Goal.java:573)
        at org.apache.maven.plugin.PluginManager.attainGoals(PluginManager.java:671)
        at org.apache.maven.MavenSession.attainGoals(MavenSession.java:263)
        at org.apache.maven.cli.App.doMain(App.java:488)
        at org.apache.maven.cli.App.main(App.java:1239)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at com.werken.forehead.Forehead.run(Forehead.java:551)
        at com.werken.forehead.Forehead.main(Forehead.java:581)

build:
----------------------------------
----------------------------------
solution : 鍗囩駭hiberate verion 2.1.8
----------------------------------
----------------------------------
鏀筸aven 錛歱roject.xml
<dependency>
   <groupId>hibernate</groupId>
   <artifactId>hibernate</artifactId>
   <version>2.1.8</version>
   <properties>
    <ejb.manifest.classpath>true</ejb.manifest.classpath>
   </properties>
  </dependency>

榪欐牱鍐欙紝涔熸槸娌℃湁闂鐨?BR><discriminator type="java.lang.String" column="REGION_TYPE" length="10"/>



java鍏夌幆 2005-08-19 13:52 鍙戣〃璇勮
]]>
hiberante persistencehttp://m.tkk7.com/andyj2ee/archive/2005/05/12/4238.htmljava鍏夌幆java鍏夌幆Thu, 12 May 2005 10:38:00 GMThttp://m.tkk7.com/andyj2ee/archive/2005/05/12/4238.htmlhttp://m.tkk7.com/andyj2ee/comments/4238.htmlhttp://m.tkk7.com/andyj2ee/archive/2005/05/12/4238.html#Feedback0http://m.tkk7.com/andyj2ee/comments/commentRss/4238.htmlhttp://m.tkk7.com/andyj2ee/services/trackbacks/4238.html you had a table "miners" that looked like this 
create table miners (
   id BIGINT NOT NULL AUTO_INCREMENT,
   first_name VARCHAR(
255),
   last_name VARCHAR(
255),
   primary key (id)
)
 
Hibernate class (Miner.java) specifies the fields, getters/setters and xdoclet tags looks like so.
package deadwood;
/**
 * @hibernate.class table="miners"
 
*/

public class Miner {
    
private Long id;
    
private String firstName;
    
private String lastName;
    
/**
     * @hibernate.id generator-class="native"
     
*/

    
public Long getId() return id; }
    
public void setId(Long id) this.id = id; }

    
/**
     * @hibernate.property column="first_name"
     
*/

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

    
/**
     * @hibernate.property column="last_name"
     
*/

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

 

Associations

 the Miner class we looked at was single table oriented, mapping to a single miners table. ORM solutions support ways to map associated tables to in memory objects ,
 

  • Many to One/One to one - belongs_to/has_one
  • One to Many (set) - has_many
  • Many to Many (set) - has_and_belongs_to_many
  • Single Table Inheritance
  • Components (mapping > 1 object per table)

 As a comparative example, lets look at the many to one relationship. We are going to expand our Deadwood example from part I. We add to the Miner a many to one association with a GoldClaim object. This means there is a foreign key, gold_claim_id in the miners table, which links it to a row in the gold_claims table.

(Java)
public class Miner {
   
// Other fields/methods omitted

    
private GoldClaim goldClaim;
    
/**
     * @hibernate.many-to-one column="gold_claim_id"
     *         cascade="save"
     
*/

    
public GoldClaim getGoldClaim() return goldClaim; }
    
public void setGoldClaim(GoldClaim goldClaim) {
        
this.goldClaim = goldClaim;
    }

}
Hibernate uses explicit mapping to specify the foreign key column, as well as the cascade behavior, which we will talk about next. Saving a Miner will save its associated GoldClaim, but updates and deletes to it won't affect the associated object.

 Transitive Persistence  
Its important for an ORM solution to provide a way to detect and cascade changes from in memory objects to the database, without the need to manually save() each one. Hibernate features a flexible and powerful version of this via declarative cascading persistence. 

Deleting Hibernate offers a number of different cascading behaviors for all associations types, giving it a high degree of flexibility. For example, setting cascade="all" will make GoldClaim save, update and delete along with its parent Miner, like so...

Miner miner = new Miner();
miner.setGoldClaim(
new GoldClaim());
session.save(miner); 
// Saves Miner and GoldClaim objects.
session.delete(miner); // Deletes both of them.
By using the cascade="save-update", you could get this behavior on any association, regardless of which table the foreign key lives in. Hibernate doesn't base the transistive persistence behavior off the relationship type, but rather the cascade style, which is much more fine grained and powerful. 

Query Languages

 Hibernate has its own object oriented query language (Hibernate Query Language - HQL), which is deliberately very similar to SQL. How it differs is that it lets developers express their queries in terms of objects and fields instead of tables and columns. Hibernate translates the query into SQL optimized for your particular database. Obviously, inventing a new query language is very substantial task, but the expressiveness and power of it is one of Hibernate's selling points. 

Querying for Objects with HQL 
when you have to start navigating across objects with SQL, HQL can be very convenient alternative. Let's take a look at our sample queries for HQL.

// Find first Miner by name
Query q = session.createQuery("from Miner m where m.firstName = :name");
q.setParameter(
"name""Elma");
Miner m 
= (Miner) q.setMaxResults(1).uniqueResult();

// Finds up to 10 miners older than 30, ordered by age.
Integer age = new Integer(30);
Query q 
= session.createQuery(
    
"from Miner m where m.age > :age order by age asc");
List miners 
= q.setParameter("age", age).setMaxResults(10).list();

// Similar to join query above, but no need to manually join
Query q = session.createQuery(
   
"from Miner m where m.goldClaim.squareArea = :area");
List minersWithSqA 
= q.setParameter("area"new Integer(1000)).list();

 Having covered some of the basics of fetching objects, let's turn your attention to how we can make fetching objects fast. The next section covers the means by which we can tune the performance. 

Performance Tuning

 Beyond just mapping objects to tables, robust ORM solutions need to provide ways to tune the performance of the queries. One of the risks of working with ORM's is that you often pull back too much data from the database. This tends to happen because it its very easy to pull back several thousand rows, with multiple SQL queries, with a simple statement like "from Miner". Common ORM strategies for dealing with this include Lazy fetching, outer join fetching and caching. 

What I mean by lazy is that when you fetch an object, the ORM tool doesn't fetch data from other tables, until you request the association. This prevents loading to much unneeded data.  Hibernate allows you to choose which associations are lazy.  This leads us to one of the great fallacies of ORM, that Lazy loading is always good. In reality, lazy loading is only good if you didn't need the data. Otherwise, you are doing with 2-1000+ queries what you could have done with one. This is dreaded N+1 select problem, where to get all the objects require N selects + 1 original selects. This problem gets much worse when you deal with collections..

Outer Joins and Explicit Fetching

Generally, one of the best way to improve performance is to limit the number of trips to the database. Better 1 big query than a few small ones. Hibernate has a number ways its handles the N+1 issue. Associations can be explicitly flagged for outer join fetching (via outer-join="true"), and you can add outer join fetching to HQL statements. For example...

/**
* @hibernate.many-to-one column="gold_claim_id"
*           cascade="save-update" outer-join="true"
*/

public GoldClaim getGoldClaim() return goldClaim;  }

// This does one select and fetches both the Miner and GoldClaim
// and maps them correctly.
Miner m = (Miner) session.load(Miner.classnew Long(1));
In addition, when selecting lists or dealing with collection associations, you can use an explicit outer join fetch, like so...
// Issues a single select, instead of 1 + N (where N is the # miners)
List list = session.find("from Miner m left join fetch m.goldClaim");
The performance savings from this can very significant. 

Caching

While object caching isn't always going to be helpful or a performance silver bullet, Hibernate has a huge potential advantage here. It provides several levels of caching, including a session (UnitOfWork) level as well as an optional second level cache. You always use the '1st level' cache, as it prevents circular references and multiple trips to the database for the same object. Using a second level cache can allow much of the database state to stay resident in memory. This is especially useful for frequently read and reference data.



java鍏夌幆 2005-05-12 18:38 鍙戣〃璇勮
]]>
鍏充簬cascade 涓巌nversehttp://m.tkk7.com/andyj2ee/archive/2005/04/15/3313.htmljava鍏夌幆java鍏夌幆Fri, 15 Apr 2005 07:09:00 GMThttp://m.tkk7.com/andyj2ee/archive/2005/04/15/3313.htmlhttp://m.tkk7.com/andyj2ee/comments/3313.htmlhttp://m.tkk7.com/andyj2ee/archive/2005/04/15/3313.html#Feedback0http://m.tkk7.com/andyj2ee/comments/commentRss/3313.htmlhttp://m.tkk7.com/andyj2ee/services/trackbacks/3313.html鐪嬭創璁板綍錛?BR>
 鍦ㄧ粷澶у鏁幫紙100%錛燂級鎯呭喌涓嬶紝many-to-many鐨刢ascade閮戒細璁劇疆涓?save-update"錛?
姣斿User鍜孯ole鏄痬any-to-many鐨勶紝浣犱笉鍙兘鍦ㄥ垹闄や竴涓猂ole鏃訛紝鎶婂畠鐨勬墍鏈塙ser閮藉垹闄ゅ惂錛屽弽涔嬩篃涓嶅彲鑳姐?nbsp;

鍙屽悜鐨刴any-to-many緇存姢璧鋒潵紜疄姣旇緝楹葷儲錛屼笖鏁堢巼鍙兘姣旇緝浣庛?
浣嗘垜濮嬬粓榪樻槸鍧氭寔涓涓師鍒欙細鍙屽悜鍏寵仈涓瀹氳涓杈硅緗負inverse="true"錛屾洿鏂版椂涓よ竟涓璧鋒洿鏂般傛垜浠庢潵娌℃湁閬囧埌榪?SPAN style="FONT-WEIGHT: bold">榪濆弽澶栭敭
鐨勬儏鍐點?/SPAN> 

浠庡叧緋繪湰韜潵璁詫紝涓瀵瑰錛屽瀵逛竴鐨勫叧緋繪湰韜兘鏄敱澶氱殑涓鏂規潵緇存姢鐨勶紝
澶氬澶氭槸鐢卞弻鏂規潵緇存姢鐨?/SPAN>


]]>
主站蜘蛛池模板: 日韩精品无码免费视频| 国产真人无码作爱视频免费| 亚洲精品综合久久| 久久99免费视频| 亚洲伦理中文字幕| 国产亚洲福利一区二区免费看| 久久精品免费大片国产大片| 亚洲午夜视频在线观看| 日韩在线视频免费看| 中文字幕无线码中文字幕免费| 亚洲欧洲精品在线| | 色噜噜综合亚洲av中文无码| 国拍在线精品视频免费观看| 特级aaaaaaaaa毛片免费视频| 亚洲视频在线播放| 国产免费人视频在线观看免费 | 免费看黄网站在线看| 亚洲综合激情九月婷婷| 免费国产成人高清在线观看麻豆| 无码av免费一区二区三区| 亚洲人成未满十八禁网站| 亚洲AV午夜福利精品一区二区| 成熟女人牲交片免费观看视频| a级毛片在线免费| 亚洲精品国产高清在线观看| 亚洲一区二区三区日本久久九| 又粗又黄又猛又爽大片免费| 麻豆视频免费观看| 久久青草国产免费观看| 免费毛片毛片网址| 亚洲 日韩经典 中文字幕| 亚洲成AV人在线观看天堂无码| 国产免费拔擦拔擦8x| 中文字幕无码视频手机免费看 | 中文字幕中韩乱码亚洲大片| 午夜精品免费在线观看| 曰批全过程免费视频免费看 | baoyu116.永久免费视频| 亚洲精品中文字幕无码A片老| 亚洲国产精品热久久|