-->
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.  [ 14 posts ] 
Author Message
 Post subject: Bitte um Erklärungen
PostPosted: Wed Dec 06, 2006 9:11 am 
Newbie

Joined: Fri Dec 01, 2006 5:50 am
Posts: 7
Hallo zusammen,

benutze erst seit kurzem Hibernate und hätte ein paar Fragen zu Problemen auf die ich gestoßen bin. Wär nett wenn ihr mir helfen könntet.

Erstes Problem:
Ich habe eine Methode selectInterface(int id)

public InterfaceHB selectInterface(final int id) {
InterfaceHB hb = new InterfaceHB();
Transaction tx = null;
Session session = HibernateSessionFactory.getInstance().getCurrentSession();
try {
tx = session.beginTransaction();
hb = (InterfaceHB) session.load(InterfaceHB.class, id);
tx.commit();
} catch (HibernateException e) {
e.printStackTrace();
if (tx != null && tx.isActive()) {
tx.rollback();
}
}
return hb;
}


führe ich diese Methode aus bekomme ich immer den Fehler

could not initialize proxy - the owning Session was closed

lasse ich jedoch das tx.commit() weg funktioniert meine Methode. Aber das commit ist doch wichtig oder, da es meine Session beendet, oder hab ich das falsch verstanden?

Komischerweise wenn ich in obigen Code vor tx.commit() einfach String test = hb.getDate(); funktioniert es auch, ergibt doch keinen Sinn oder?

2.
Ist es möglich mit Hibernate auch 2 Primary Keys abzubilden, falls ja vielleicht hat jemand einem Link zu einem Beispiel, hab nämlich leider bis jetzt noch nichts gefunden.

Danke für Eure Hilfe
Gruß Markus


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 10:28 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Ist das die einzige Methode, die aufgerufen wird im Rahmen eines Tests? Passiert die Ausnahme wirklich an dieser Stelle?
was passiert wenn Du session.close nach dem Commit aufrufst.

Kannst Du mal die hibernate.cfg.xml posten.

2 pk = composite-id -> Hibernate Reference

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 11:32 am 
Newbie

Joined: Fri Dec 01, 2006 5:50 am
Posts: 7
session.close bringt leider auch nichts
nein ist nicht die einzige Methode, bei Auflisten, createn, deleten und updaten funktionierts nur nicht bei select.

hier ist meine hibernate.cfg.xml


<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
<property name="connection.username">hr</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="connection.password">hr</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<!-- thread is the short name for
org.hibernate.context.ThreadLocalSessionContext
and let Hibernate bind the session automatically to the thread
-->
<property name="current_session_context_class">thread</property>
<!-- this will show us all sql statements -->
<property name="hibernate.show_sql">true</property>

<!-- mapping files -->
<mapping resource="com/msg/iat/hibernate/administration/System.hbm.xml" />
<mapping resource="com/msg/iat/hibernate/administration/Attribute.hbm.xml" />
<mapping resource="com/msg/iat/hibernate/administration/Interface.hbm.xml" />
<mapping resource="com/msg/iat/hibernate/administration/Process.hbm.xml" />
<mapping resource="com/msg/iat/hibernate/administration/ProcessInterfaceRelation.hbm.xml" />
<mapping resource="com/msg/iat/hibernate/administration/Message.hbm.xml" />
</session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 6:22 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Bleibt die Frage wo der Fehler passiert? Poste bitte mal Stacktrace und so wie es überall steht Mapping, sessionFactory ....

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 3:56 am 
Newbie

Joined: Fri Dec 01, 2006 5:50 am
Posts: 7
08:53:18,687 INFO [STDOUT] 08:53:18,687 INFO [StartupServletContextListener] ServletContext 'D:\Programme\Jboss4\server\default\.\tmp\deploy\tmp19132InterfaceAnalysisTool-exp.war\' initialized.
08:53:24,484 INFO [STDOUT] 08:53:24,484 INFO [[/InterfaceAnalysisTool]] No state saving method defined, assuming default server state saving
08:53:26,359 INFO [STDOUT] 08:53:26,359 INFO [MyfacesConfig] No context init parameter 'org.apache.myfaces.PRETTY_HTML' found, using default value true
08:53:26,359 INFO [STDOUT] 08:53:26,359 INFO [MyfacesConfig] No context init parameter 'org.apache.myfaces.ALLOW_JAVASCRIPT' found, using default value true
08:53:26,359 INFO [STDOUT] 08:53:26,359 INFO [MyfacesConfig] No context init parameter 'org.apache.myfaces.DETECT_JAVASCRIPT' found, using default value false
08:53:26,359 INFO [STDOUT] 08:53:26,359 INFO [MyfacesConfig] No context init parameter 'org.apache.myfaces.AUTO_SCROLL' found, using default value false
08:53:39,343 INFO [STDOUT] 08:53:39,343 INFO [Environment] Hibernate 3.1.3
08:53:39,375 INFO [STDOUT] 08:53:39,375 INFO [Environment] hibernate.properties not found
08:53:39,375 INFO [STDOUT] 08:53:39,375 INFO [Environment] using CGLIB reflection optimizer
08:53:39,375 INFO [STDOUT] 08:53:39,375 INFO [Environment] using JDK 1.4 java.sql.Timestamp handling
08:53:39,703 INFO [STDOUT] 08:53:39,703 INFO [Configuration] configuring from resource: /hibernate.cfg.xml
08:53:39,703 INFO [STDOUT] 08:53:39,703 INFO [Configuration] Configuration resource: /hibernate.cfg.xml
08:53:40,031 INFO [STDOUT] 08:53:40,031 INFO [Configuration] Reading mappings from resource: com/msg/iat/hibernate/administration/System.hbm.xml
08:53:40,296 INFO [STDOUT] 08:53:40,296 INFO [HbmBinder] Mapping class: com.msg.iat.hibernate.administration.SystemHB -> iasystem
08:53:40,375 INFO [STDOUT] 08:53:40,375 INFO [Configuration] Reading mappings from resource: com/msg/iat/hibernate/administration/Attribute.hbm.xml
08:53:40,406 INFO [STDOUT] 08:53:40,406 INFO [HbmBinder] Mapping class: com.msg.iat.hibernate.administration.AttributeHB -> business_attributes
08:53:40,421 INFO [STDOUT] 08:53:40,421 INFO [Configuration] Reading mappings from resource: com/msg/iat/hibernate/administration/Interface.hbm.xml
08:53:40,437 INFO [STDOUT] 08:53:40,437 INFO [HbmBinder] Mapping class: com.msg.iat.hibernate.administration.InterfaceHB -> interfaces
08:53:40,500 INFO [STDOUT] 08:53:40,500 INFO [HbmBinder] Mapping collection: com.msg.iat.hibernate.administration.InterfaceHB.processes -> processinterface
08:53:40,515 INFO [STDOUT] 08:53:40,515 INFO [Configuration] Reading mappings from resource: com/msg/iat/hibernate/administration/Process.hbm.xml
08:53:40,546 INFO [STDOUT] 08:53:40,546 INFO [HbmBinder] Mapping class: com.msg.iat.hibernate.administration.ProcessHB -> processes
08:53:40,546 INFO [STDOUT] 08:53:40,546 INFO [Configuration] Reading mappings from resource: com/msg/iat/hibernate/administration/ProcessInterfaceRelation.hbm.xml
08:53:40,562 INFO [STDOUT] 08:53:40,562 INFO [HbmBinder] Mapping class: com.msg.iat.hibernate.administration.ProcessInterfaceRelationHB -> processinterfacerelation
08:53:40,562 INFO [STDOUT] 08:53:40,562 INFO [Configuration] Reading mappings from resource: com/msg/iat/hibernate/administration/Message.hbm.xml
08:53:40,593 INFO [STDOUT] 08:53:40,593 INFO [HbmBinder] Mapping class: com.msg.iat.hibernate.administration.MessageHB -> messages
08:53:40,593 INFO [STDOUT] 08:53:40,593 INFO [Configuration] Configured SessionFactory: null
08:53:41,031 INFO [STDOUT] 08:53:41,031 INFO [DriverManagerConnectionProvider] Using Hibernate built-in connection pool (not for production use!)
08:53:41,031 INFO [STDOUT] 08:53:41,031 INFO [DriverManagerConnectionProvider] Hibernate connection pool size: 20
08:53:41,031 INFO [STDOUT] 08:53:41,031 INFO [DriverManagerConnectionProvider] autocommit mode: false
08:53:41,046 INFO [STDOUT] 08:53:41,046 INFO [DriverManagerConnectionProvider] using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@localhost:1521:XE
08:53:41,046 INFO [STDOUT] 08:53:41,046 INFO [DriverManagerConnectionProvider] connection properties: {user=hr, password=hr}
08:53:41,796 INFO [STDOUT] 08:53:41,796 INFO [SettingsFactory] RDBMS: Oracle, version: Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
08:53:41,796 INFO [STDOUT] 08:53:41,796 INFO [SettingsFactory] JDBC driver: Oracle JDBC driver, version: 10.2.0.1.0XE
08:53:41,890 INFO [STDOUT] 08:53:41,890 INFO [Dialect] Using dialect: org.hibernate.dialect.Oracle9Dialect
08:53:41,906 INFO [STDOUT] 08:53:41,906 INFO [TransactionFactoryFactory] Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
08:53:41,921 INFO [STDOUT] 08:53:41,921 INFO [TransactionManagerLookupFactory] No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
08:53:41,921 INFO [STDOUT] 08:53:41,921 INFO [SettingsFactory] Automatic flush during beforeCompletion(): disabled
08:53:41,921 INFO [STDOUT] 08:53:41,921 INFO [SettingsFactory] Automatic session close at end of transaction: disabled
08:53:41,921 INFO [STDOUT] 08:53:41,921 INFO [SettingsFactory] JDBC batch size: 15
08:53:41,921 INFO [STDOUT] 08:53:41,921 INFO [SettingsFactory] JDBC batch updates for versioned data: disabled
08:53:41,921 INFO [STDOUT] 08:53:41,921 INFO [SettingsFactory] Scrollable result sets: enabled
08:53:41,921 INFO [STDOUT] 08:53:41,921 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): enabled
08:53:41,921 INFO [STDOUT] 08:53:41,921 INFO [SettingsFactory] Connection release mode: auto
08:53:41,937 INFO [STDOUT] 08:53:41,937 INFO [SettingsFactory] Default batch fetch size: 1
08:53:41,937 INFO [STDOUT] 08:53:41,937 INFO [SettingsFactory] Generate SQL with comments: disabled
08:53:41,937 INFO [STDOUT] 08:53:41,937 INFO [SettingsFactory] Order SQL updates by primary key: disabled
08:53:41,937 INFO [STDOUT] 08:53:41,937 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
08:53:42,000 INFO [STDOUT] 08:53:42,000 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
08:53:42,000 INFO [STDOUT] 08:53:42,000 INFO [SettingsFactory] Query language substitutions: {}
08:53:42,000 INFO [STDOUT] 08:53:42,000 INFO [SettingsFactory] Second-level cache: enabled
08:53:42,000 INFO [STDOUT] 08:53:42,000 INFO [SettingsFactory] Query cache: disabled
08:53:42,000 INFO [STDOUT] 08:53:42,000 INFO [SettingsFactory] Cache provider: org.hibernate.cache.EhCacheProvider
08:53:42,015 INFO [STDOUT] 08:53:42,015 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
08:53:42,015 INFO [STDOUT] 08:53:42,015 INFO [SettingsFactory] Structured second-level cache entries: disabled
08:53:42,046 INFO [STDOUT] 08:53:42,046 INFO [SettingsFactory] Echoing all SQL to stdout
08:53:42,046 INFO [STDOUT] 08:53:42,046 INFO [SettingsFactory] Statistics: disabled
08:53:42,062 INFO [STDOUT] 08:53:42,062 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
08:53:42,062 INFO [STDOUT] 08:53:42,062 INFO [SettingsFactory] Default entity-mode: pojo
08:53:42,125 INFO [STDOUT] 08:53:42,125 INFO [SessionFactoryImpl] building session factory
08:53:42,156 INFO [STDOUT] 08:53:42,156 WARN [Configurator] No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/D:/Programme/Jboss4/server/default/tmp/deploy/tmp19132InterfaceAnalysisTool-exp.war/WEB-INF/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
08:53:43,671 INFO [STDOUT] 08:53:43,671 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
08:53:44,968 INFO [STDOUT] Hibernate: select interfaceh0_.id as id2_, interfaceh0_.validfrom as validfrom2_, interfaceh0_.name as name2_, interfaceh0_.description as descript4_2_, interfaceh0_.validto as validto2_ from interfaces interfaceh0_
08:53:54,593 INFO [STDOUT] Hibernate: select interfaceh0_.id as id2_, interfaceh0_.validfrom as validfrom2_, interfaceh0_.name as name2_, interfaceh0_.description as descript4_2_, interfaceh0_.validto as validto2_ from interfaces interfaceh0_
08:53:54,750 INFO [STDOUT] 08:53:54,734 ERROR [LazyInitializationException] could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:56)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:98)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:158)
at com.msg.iat.hibernate.administration.InterfaceHB$$EnhancerByCGLIB$$88442fea.getDescription(<generated>)
at com.msg.iat.ba.administration.InterfaceBA.selectInterface(InterfaceBA.java:69)
at com.msg.iat.facade.AdministrationFacade.selectInterface(AdministrationFacade.java:149)
at com.msg.iat.gui.administration.InterfaceMB.selectInterface(InterfaceMB.java:182)
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:585)
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)
at javax.faces.component.UICommand.broadcast(UICommand.java:86)
at javax.faces.component.UIData.broadcast(UIData.java:338)
at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:90)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:164)
at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:316)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:106)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:122)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)
08:53:54,750 INFO [STDOUT] 08:53:54,750 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
javax.faces.el.EvaluationException: Exception while invoking expression #{interfaceBean.selectInterface}
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:153)
at javax.faces.component.UICommand.broadcast(UICommand.java:86)
at javax.faces.component.UIData.broadcast(UIData.java:338)
at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:90)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:164)
at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:316)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:106)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:122)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)
Caused by: org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:56)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:98)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:158)
at com.msg.iat.hibernate.administration.InterfaceHB$$EnhancerByCGLIB$$88442fea.getDescription(<generated>)
at com.msg.iat.ba.administration.InterfaceBA.selectInterface(InterfaceBA.java:69)
at com.msg.iat.facade.AdministrationFacade.selectInterface(AdministrationFacade.java:149)
at com.msg.iat.gui.administration.InterfaceMB.selectInterface(InterfaceMB.java:182)
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:585)
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)
... 28 more


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 4:48 am 
Newbie

Joined: Wed Jul 26, 2006 6:01 am
Posts: 10
Benutz du ein SessionFilter?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 9:04 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Sorry, ich kann Dir nicht weiterhelfen. Es fehlen Informationen, die man laut den Posthinweisen posten soll, um Die ich Dich auch nochmal gebeten habe, aber die Du einfach nicht bereitstellt.

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 10:15 am 
Newbie

Joined: Fri Dec 01, 2006 5:50 am
Posts: 7
Tschuldige, dass ich nicht alles gepostet habe, also hier nochmal meine SessionFactory und meine mapping.xml

noch eine Frage habe gesehen, dass man bei hibernate auch nativeSQL einsetzen kann, hab es mal kurz ausprobiert. Select funktioniert wunderbar mit dem Befehl session.createSQLQuery.
Welchen Befehl muss ich jedoch zum updaten benutzen?

was meinst du mit SessionFilter?

Danke für Eure Mühen bisher


package com.msg.iat.utill;
import javax.naming.InitialContext;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
/**
* @author hennebrueder This class garanties that only one single SessionFactory
* is instanciated and that the configuration is done thread safe as
* singleton. Actually it only wraps the Hibernate SessionFactory.
* When a JNDI name is configured the session is bound to to JNDI,
* else it is only saved locally.
* You are free to use any kind of JTA or Thread transactionFactories.
*/
public class HibernateSessionFactory {
/**
* Default constructor.
*/
private HibernateSessionFactory() {
}
/**
* Location of hibernate.cfg.xml file. NOTICE: Location should be on the
* classpath as Hibernate uses #resourceAsStream style lookup for its
* configuration file. That is place the config file in a Java package - the
* default location is the default Java package.<br>
* <br>
* Examples: <br>
* <code>CONFIG_FILE_LOCATION = "/hibernate.conf.xml".
* CONFIG_FILE_LOCATION = "/com/foo/bar/myhiberstuff.conf.xml".</code>
*/
private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
/** The single instance of hibernate configuration */
private static final Configuration cfg = new Configuration();
/** The single instance of hibernate SessionFactory */
private static org.hibernate.SessionFactory sessionFactory;
/**
* initialises the configuration if not yet done and returns the current
* instance
*
* @return
*/
public static SessionFactory getInstance() {
if (sessionFactory == null)
initSessionFactory();
return sessionFactory;
}
/**
* Returns the ThreadLocal Session instance. Lazy initialize the
* <code>SessionFactory</code> if needed.
*
* @return Session
* @throws HibernateException
*/
public Session openSession() {
return sessionFactory.getCurrentSession();
}
/**
* The behaviour of this method depends on the session context you have
* configured. This factory is intended to be used with a hibernate.cfg.xml
* including the following property <property
* name="current_session_context_class">thread</property> This would return
* the current open session or if this does not exist, will create a new
* session
*
* @return
*/
public Session getCurrentSession() {
return sessionFactory.getCurrentSession();
}
/**
* initializes the sessionfactory in a safe way even if more than one thread
* tries to build a sessionFactory
*/
private static synchronized void initSessionFactory() {
/*
* [laliluna] check again for null because sessionFactory may have been
* initialized between the last check and now
*
*/
Logger log = Logger.getLogger(HibernateSessionFactory.class);
if (sessionFactory == null) {
try {
cfg.configure(CONFIG_FILE_LOCATION);
String sessionFactoryJndiName = cfg.getProperty(Environment.SESSION_FACTORY_NAME);
if (sessionFactoryJndiName != null) {
cfg.buildSessionFactory();
log.debug("get a jndi session factory");
sessionFactory = (SessionFactory) (new InitialContext()).lookup(sessionFactoryJndiName);
} else {
log.debug("classic factory");
sessionFactory = cfg.buildSessionFactory();
}
} catch (Exception e) {
System.err.println("%%%% Error Creating HibernateSessionFactory %%%%");
e.printStackTrace();
throw new HibernateException("Could not initialize the Hibernate configuration");
}
}
}
public static void close() {
if (sessionFactory != null)
sessionFactory.close();
sessionFactory = null;
}
}





<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class name="com.msg.iat.hibernate.administration.InterfaceHB" table="interfaces">
<id name="id" column="id" type="java.lang.Integer">
<generator class="increment"/>
</id>
<property name="validFrom" column="validfrom" type="timestamp" />
<property name="name" column="name" type="java.lang.String" />
<property name="description" column="description" type="java.lang.String" />
<property name="validTo" column="validto" type="date" />

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 1:40 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Und jetzt noch die Klasse.

Kann es sein, dass der Primary Key vom Typ int statt Integer ist?

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 08, 2006 3:42 am 
Newbie

Joined: Fri Dec 01, 2006 5:50 am
Posts: 7
Hier ist meine Klasse

package com.msg.iat.hibernate.administration;
import java.util.Date;
/**
* @author schneidm
* @version $Id$
*/
public class InterfaceHB {
/**
* the id of an InterfaceHB.
*/
private int id;
/**
* the validFrom of an InterfaceHB.
*/
private Date validFrom;
/**
* the name of an InterfaceHB.
*/
private String name;
/**
* the description of an InterfaceHB.
*/
private String description;
/**
* the validTo of an InterfaceHB.
*/
private Date validTo;
/**
* @return Returns the description.
*/
public String getDescription() {
return this.description;
}
/**
* @param description The description to set.
*/
public void setDescription(final String description) {
this.description = description;
}
/**
* @return Returns the id.
*/
public int getId() {
return this.id;
}
/**
* @param id The id to set.
*/
public void setId(final int id) {
this.id = id;
}
/**
* @return Returns the name.
*/
public String getName() {
return this.name;
}
/**
* @param name The name to set.
*/
public void setName(final String name) {
this.name = name;
}
/**
* @return Returns the validFrom.
*/
public Date getValidFrom() {
return this.validFrom;
}
/**
* @param validFrom The validFrom to set.
*/
public void setValidFrom(final Date validFrom) {
this.validFrom = validFrom;
}
/**
* @return Returns the validTo.
*/
public Date getValidTo() {
return this.validTo;
}
/**
* @param validTo The validTo to set.
*/
public void setValidTo(final Date validTo) {
this.validTo = validTo;
}

}

ja mein Primary Key ist vom Typ int, aber wenn ich auch die Interface.hbm.xml ändere, bekomme ich immer noch den selben Fehler wenn ich in der Select-Funktion tx.commit() verwende


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 09, 2006 12:15 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Ändere mal bitte die Klasse.

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 11, 2006 4:26 am 
Newbie

Joined: Fri Dec 01, 2006 5:50 am
Posts: 7
hab ich gemacht, hat leider auch nicht funktioniert.

Sehr komisch ist, dass wenn ich vor tx.commit() einfach ein simples System.out.println(hb.getName()); einfüge, gehts ohne Probleme

Ebenso wenn ich die Zeile

hb = (InterfaceHB) session.load(InterfaceHB.class, id);

ersetze duch

hb = (InterfaceHB) session.createQuery("from InterfaceHB where id = :id")
.setInteger("id", id)
.uniqueResult();

bekomm ich auch keine Fehlermeldung.

Hätt noch eine andere Frage, ist es unbedingt nötig nach tx.commit() noch session.close() auszuführen. Schließt die Session nicht schon tx.commit()?

Danke für deine Mühen bisher


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 11, 2006 4:50 am 
Newbie

Joined: Wed Jul 26, 2006 6:01 am
Posts: 10
Hi mschnei,

Nein die session wird nicht nach tx.commit() geschlossen.

So wie ich verstanden habe, machst du eine web-application.

Werden die Daten dann in einer JSP-Seite ausgegeben?

Falls ja guck dir das an: http://www.hibernate.org/43.html

Zum testen kanst du auch das Eigenschaft lazy ausprobieren.
Stells es auf false

Code:
  <class name="Classenname" lazy="false">


Mehr dazu: http://www.hibernate.org/hib_docs/v3/re ... ching-lazy

Gruss.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 12, 2006 4:19 am 
Newbie

Joined: Fri Dec 01, 2006 5:50 am
Posts: 7
ja geb die Seiten mit JSP aus.

Ok werd ich mir mal anschaun.

Danke


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 14 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.