-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Speichern von Dokumenten mittels Hobernate
PostPosted: Thu May 10, 2007 7:10 am 
Newbie

Joined: Mon Mar 26, 2007 7:50 am
Posts: 18
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2
Mapping documents:
Code:
<class name="main.org.jboss.portlet.milestone.spring.dto.EntryValues"
      table="entryValues" >
      <id column="id" name="id">
         <generator class="increment" />
      </id>
      <property name="value" column="value" type="string" not-null="false" />
      <property name="value_bool" column="value_bool" type="boolean" not-null="false" />
      <property name="value_date" column="value_date" type="date" not-null="false" />
      <property name="value_file" column="value_file" type="main.org.jboss.portlet.milestone.spring.dto.UFile" not-null="false" />
      
      <property name="selected" column="selected" type="main.org.jboss.portlet.milestone.spring.dto.Pair" not-null="false" />
      <property name="dataType" column="dataType" not-null="false"
         type="main.org.jboss.portlet.milestone.spring.dto.DataType" />
      <list name="values">
         <key column="pair_id" />
         <list-index column="pair_idx" />
         <one-to-many class="main.org.jboss.portlet.milestone.spring.dto.Pair"/>
      </list>
   </class>


Hallo Leute,

ich schreibe zur Zeit an einem Portlet, das Spring, MyFaces und Hibernate zur DB kommunikation einsetzt. Mittels des Portlets kann man unteranderem Dokumente hochladen und sie für andere (Kollegen) zugänglich machen. das klappt auch soweit alles ganz gut,
das problem ist nun wenn ich so ein EntryValue aus der DB laden möchte wird ja auch die spalte/das Attribut value_file geladen, was natürlich , wie ihr mir wohl zustimmen werdet, nicht so günstig ist...
Es tut mir leid so eine dumme frage zu stellen, aber kann mir einer einen Rat geben wie ich das unterbinden kann... so das die spalte erst geladen wird wenn sie explizit aufgerufen wird?


mfg und dank im voraus,

Omid[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 7:55 am 
Newbie

Joined: Thu May 03, 2007 2:30 am
Posts: 18
Hallo...

Du könntest das "File" Feld als eine eigene Tabelle abspeichern. Dann hast du die Möglichkeit für die Datei einfach ein Lazy Load zu implementieren.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 4:43 pm 
Newbie

Joined: Tue Aug 29, 2006 10:56 am
Posts: 15
Das sollte doch mit "lazy property fetching" gehen. Siehe dazu Kapitel 19.1.7. der Hibernate Reference.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 11, 2007 5:01 am 
Newbie

Joined: Mon Mar 26, 2007 7:50 am
Posts: 18
danke für die Antworten.

hab versucht eine one-to-one beziehung einzubauen, was auch ganz gut klappt, hier die mapping:
Code:
<class name="main.org.jboss.portlet.milestone.spring.dto.EntryValues"
      table="entryValues" >
      <id column="id" name="id">
         <generator class="increment" />
      </id>
      
      <property name="value" column="value" type="string" not-null="false" />
      <property name="value_bool" column="value_bool" type="boolean" not-null="false" />
      <property name="value_date" column="value_date" type="date" not-null="false" />
      
      <one-to-one name="value_file" class="main.org.jboss.portlet.milestone.spring.dto.UFile" cascade="persist,delete" />
      <property name="selected" column="selected" type="main.org.jboss.portlet.milestone.spring.dto.Pair" not-null="false" />
      <property name="dataType" column="dataType" not-null="false"
         type="main.org.jboss.portlet.milestone.spring.dto.DataType" />
      <list name="values">
         <key column="pair_id" />
         <list-index column="pair_idx" />
         <one-to-many class="main.org.jboss.portlet.milestone.spring.dto.Pair"/>
      </list>
   </class>
   
   <class name="main.org.jboss.portlet.milestone.spring.dto.UFile" table="ufile" lazy="true">
      <id column="id" name="id">
         <generator class="foreign">
               <param name="property">entryValues</param>
           </generator>
      </id>
      
      <property name="fileName" column="filename" type="string" />
      <property name="contentType" column="contenttype" type="string" />
      <property name="content" column="content" type="blob" lazy="true"/>
      <one-to-one name="entry_Values" class="main.org.jboss.portlet.milestone.spring.dto.EntryValues" constrained="true"/>
   </class>


nun hab ich das problem, das die datei nicht mehr in die db geschrieben wird.... ist etwas am mapping faslch???

hier mein log:

Code:
2007-05-11 14:25:49,734 DEBUG [main.org.jboss.portlet.milestone.jsf.bean.NewBean] - [buildEntryValues(Set column)] found item of type: fileattachment.
2007-05-11 14:25:49,734 DEBUG [main.org.jboss.portlet.milestone.jsf.bean.NewBean] - upload() - start
2007-05-11 14:25:49,734 DEBUG [main.org.jboss.portlet.milestone.jsf.bean.NewBean] - upload() - upload: getUploadedFile()=org.apache.myfaces.custom.fileupload.UploadedFileDefaultFileImpl@b54678
2007-05-11 14:25:49,734 DEBUG [main.org.jboss.portlet.milestone.jsf.bean.NewBean] - upload() - upload: filename=listen.pls
2007-05-11 14:25:49,734 DEBUG [main.org.jboss.portlet.milestone.jsf.bean.NewBean] - upload() - upload: contentType=audio/scpls
2007-05-11 14:25:49,734 DEBUG [main.org.jboss.portlet.milestone.jsf.bean.NewBean] - upload() - filename=listen.pls
2007-05-11 14:25:49,734 DEBUG [main.org.jboss.portlet.milestone.jsf.bean.NewBean] - created File=listen.pls
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.jsf.bean.NewBean] - created outStream=java.io.FileOutputStream@125a910
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.jsf.bean.NewBean] - fileSize=73 uploadedFile=73
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.jsf.bean.NewBean] - upload() - end
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.spring.dto.EntryValues] - Entering EntryValues.setValue_file=main.org.jboss.portlet.milestone.spring.dto.UFile@17e79d3
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.spring.dto.EntryValues] - Entering EntryValues.getValue_file
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.spring.dto.EntryValues] - [getValue_file()] filename: listen.pls
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.spring.dto.EntryValues] - Entering EntryValues.getValue_file
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.spring.dto.EntryValues] - [getValue_file()] filename: listen.pls
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.jsf.bean.NewBean] - ---------------------------->listen.pls - 73
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.jsf.bean.NewBean] - user is null, trying to resolve username...
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.jsf.facade.FacadeService] - receiving mileStoneService...
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.spring.service.MileStoneService] - receiving userManager...
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.spring.security.persistance.UserManager] - Entering UserManager.isUserAuthenticated()
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.spring.security.persistance.UserManager] - ...receiving SecurityContext
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.spring.security.persistance.UserManager] - ...receiving UserDetails: manager
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.spring.security.dto.User] - User.equals: manager == manager
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.spring.security.persistance.UserManager] - return User: manager
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.jsf.bean.NewBean] - got User: main.org.jboss.portlet.milestone.spring.security.dto.User@ecbb6e
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.jsf.bean.NewBean] - got User: main.org.jboss.portlet.milestone.spring.security.dto.User@ecbb6e
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.jsf.bean.NewBean] - [saveEntry()] entry created by user: manager
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.jsf.bean.NewBean] - [saveEntry()] entry with 2 items
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.jsf.facade.FacadeService] - receiving mileStoneService...
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.spring.persistence.EntryManager] - Calling EntryManager.saveEntry
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.spring.persistence.EntryManager] - entry=main.org.jboss.portlet.milestone.spring.dto.Entry@160de7c
localEntry=main.org.jboss.portlet.milestone.spring.dto.Entry@160de7c
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.spring.dto.EntryValues] - Entering EntryValues.getValue_file
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.spring.dto.EntryValues] - [getValue_file()] filename: listen.pls
2007-05-11 14:25:49,750 DEBUG [main.org.jboss.portlet.milestone.spring.persistence.EntryManager] - -------FILE-------->73
2007-05-11 14:25:49,750 DEBUG [org.hibernate.impl.SessionImpl] - opened session at timestamp: 11788737497
2007-05-11 14:25:49,750 DEBUG [org.hibernate.id.IncrementGenerator] - fetching initial value: select max(id) from entry
2007-05-11 14:25:49,750 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2007-05-11 14:25:49,750 DEBUG [org.hibernate.jdbc.ConnectionManager] - opening JDBC connection
2007-05-11 14:25:49,750 DEBUG [org.hibernate.SQL] - select max(id) from entry
2007-05-11 14:25:49,750 DEBUG [org.hibernate.id.IncrementGenerator] - first free id: 1
2007-05-11 14:25:49,750 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2007-05-11 14:25:49,750 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - generated identifier: 1, using strategy: org.hibernate.id.IncrementGenerator
2007-05-11 14:25:49,750 DEBUG [org.hibernate.id.IncrementGenerator] - fetching initial value: select max(id) from entryValues
2007-05-11 14:25:49,750 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2007-05-11 14:25:49,750 DEBUG [org.hibernate.SQL] - select max(id) from entryValues
2007-05-11 14:25:49,765 DEBUG [org.hibernate.id.IncrementGenerator] - first free id: 1
2007-05-11 14:25:49,765 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2007-05-11 14:25:49,765 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - generated identifier: 1, using strategy: org.hibernate.id.IncrementGenerator
2007-05-11 14:25:49,765 DEBUG [main.org.jboss.portlet.milestone.spring.dto.EntryValues] - Entering EntryValues.getValue_file
2007-05-11 14:25:49,765 DEBUG [main.org.jboss.portlet.milestone.spring.dto.EntryValues] - [getValue_file()] no file in entryvalue. looking for it in Portletsession...
2007-05-11 14:25:49,765 INFO [main.org.jboss.portlet.milestone.spring.dto.EntryValues] - *value_file*=main.org.jboss.portlet.milestone.spring.dto.UFile@17e79d3
2007-05-11 14:25:49,765 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - generated identifier: 2, using strategy: org.hibernate.id.IncrementGenerator
2007-05-11 14:25:49,765 DEBUG [main.org.jboss.portlet.milestone.spring.dto.EntryValues] - Entering EntryValues.getValue_file
2007-05-11 14:25:49,765 DEBUG [main.org.jboss.portlet.milestone.spring.dto.EntryValues] - [getValue_file()] filename: listen.pls
2007-05-11 14:25:49,765 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] - processing flush-time cascades
2007-05-11 14:25:49,765 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] - dirty checking collections
2007-05-11 14:25:49,765 DEBUG [org.hibernate.engine.Collections] - Collection found: [main.org.jboss.portlet.milestone.spring.dto.Entry.entries#1], was: [<unreferenced>] (initialized)
2007-05-11 14:25:49,765 DEBUG [main.org.jboss.portlet.milestone.spring.dto.EntryValues] - Entering EntryValues.getValue_file
2007-05-11 14:25:49,765 DEBUG [main.org.jboss.portlet.milestone.spring.dto.EntryValues] - [getValue_file()] filename: listen.pls
2007-05-11 14:25:49,765 DEBUG [main.org.jboss.portlet.milestone.spring.dto.EntryValues] - Entering EntryValues.getValue_file
2007-05-11 14:25:49,765 DEBUG [main.org.jboss.portlet.milestone.spring.dto.EntryValues] - [getValue_file()] filename: listen.pls
2007-05-11 14:25:49,765 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] - Flushed: 3 insertions, 0 updates, 0 deletions to 3 objects
2007-05-11 14:25:49,765 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] - Flushed: 1 (re)creations, 0 updates, 0 removals to 1 collections
2007-05-11 14:25:49,765 DEBUG [org.hibernate.pretty.Printer] - listing entities:
2007-05-11 14:25:49,765 DEBUG [main.org.jboss.portlet.milestone.spring.dto.EntryValues] - Entering EntryValues.getValue_file
2007-05-11 14:25:49,765 DEBUG [main.org.jboss.portlet.milestone.spring.dto.EntryValues] - [getValue_file()] filename: listen.pls

Hier ist UFile#null

2007-05-11 14:25:49,765 DEBUG [org.hibernate.pretty.Printer] - main.org.jboss.portlet.milestone.spring.dto.EntryValues{id=1, dataType=2c6d8085f3f280ccede1e9eeaeeff2e7aeeae2eff3f3aef0eff2f4ece5f4aeede9ece5f3f4efeee5aef3f0f2e9eee7aee4f4efaee4e1f4e1f4f9f0e5f3aee9eef0f5f4aed0ece1e9eef4e5f8f4dff3e9eee7ece548b23b1a4f0a1f8c82808ada8090ede1eee4e1f4eff2f9dff3f4e1f4f5f3c9808aede1f8dfece5eee7f4e8c98084f3e9fae5cc808ce4e5e6e1f5ecf4d6e1ecf5e5f48092cceae1f6e1afece1eee7afd3f4f2e9eee7bbcc8082e9e4f48093cceae1f6e1afece1eee7afc9eef4e5e7e5f2bbcc8085ece1e2e5ecf180fe8081cc8084eee1ede5f180fe8081cc8088f0eff3e9f4e9efeef180fe8082cc8084f4f9f0e5f180fe8081cc8085f6e1ecf5e5f180fe8081f8f0818080808e8080808ef48085f3e4f3e5e5f3f28091eae1f6e1aeece1eee7aec9eef4e5e7e5f292622024770107b8828081c98085f6e1ecf5e5f8f28090eae1f6e1aeece1eee7aecef5ede2e5f2062c159d8b14600b828080f8f080808081f48084f3e4f3e4f48091f0ece1e9eef4e5f8f4dff3e9eee7ece5b0f3f180fe808580808080f48090f0ece1e9eef4e5f8f4dff3e9eee7ece5f0, selected=null, values=null, value_file=main.org.jboss.portlet.milestone.spring.dto.UFile#null, value_date=null, value=sdsee, value_bool=null}
2007-05-11 14:25:49,765 DEBUG [main.org.jboss.portlet.milestone.spring.dto.EntryValues] - Entering EntryValues.getValue_file
2007-05-11 14:25:49,765 DEBUG [main.org.jboss.portlet.milestone.spring.dto.EntryValues] - [getValue_file()] filename: listen.pls
2007-05-11 14:25:49,765 DEBUG [org.hibernate.pretty.Printer] - main.org.jboss.portlet.milestone.spring.dto.EntryValues{id=2, dataType=2c6d8085f3f280caede1e9eeaeeff2e7aeeae2eff3f3aef0eff2f4ece5f4aeede9ece5f3f4efeee5aef3f0f2e9eee7aee4f4efaee4e1f4e1f4f9f0e5f3aee9eef0f5f4aec6e9ece5c1f4f4e1e3e8ede5eef4d196da736bd69690828088da8090ede1eee4e1f4eff2f9dff3f4e1f4f5f3cc8082e9e4f48093cceae1f6e1afece1eee7afc9eef4e5e7e5f2bbcc8085ece1e2e5ecf48092cceae1f6e1afece1eee7afd3f4f2e9eee7bbcc8084eee1ede5f180fe8082cc8088f0eff3e9f4e9efeef180fe8081cc8084f4f9f0e5f180fe8082cc8085f6e1ecf5e5f180fe8082cc808af6e1ecf5e5dfe6e9ece5f480b3ccede1e9eeafeff2e7afeae2eff3f3aff0eff2f4ece5f4afede9ece5f3f4efeee5aff3f0f2e9eee7afe4f4efafd5c6e9ece5bbf8f080f3f28091eae1f6e1aeece1eee7aec9eef4e5e7e5f292622024770107b8828081c98085f6e1ecf5e5f8f28090eae1f6e1aeece1eee7aecef5ede2e5f2062c159d8b14600b828080f8f080808082f48083b1b4b4f4808fe6e9ece5e1f4f4e1e3e8ede5eef4b2f3f180fe808580808081f4808ee6e9ece5e1f4f4e1e3e8ede5eef4f0f0, selected=null, values=null, value_file=main.org.jboss.portlet.milestone.spring.dto.UFile#null, value_date=null, value=listen.pls, value_bool=null}



2007-05-11 14:25:49,765 DEBUG [org.hibernate.pretty.Printer] - main.org.jboss.portlet.milestone.spring.dto.Entry{id=1, owner=main.org.jboss.portlet.milestone.spring.security.dto.User#1, entries=[main.org.jboss.portlet.milestone.spring.dto.EntryValues#1, main.org.jboss.portlet.milestone.spring.dto.EntryValues#2]}


danke,
omid


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.