GVKun编程网logo

在我的应用程序中在哪里打开和在哪里关闭SessionFactory(我的应用开启)

16

对于在我的应用程序中在哪里打开和在哪里关闭SessionFactory感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解我的应用开启,并且为您提供关于AndroidActionBar/工具栏消

对于在我的应用程序中在哪里打开和在哪里关闭SessionFactory感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解我的应用开启,并且为您提供关于Android ActionBar /工具栏消失在我的应用程序中、extjs 应用程序中的 scss 文件在哪里、Hibernate 4.0.0Final在哪里,SessionFactory.openSession(拦截器拦截器)、Hibernate 4中的SessionFactory.openSession(Connection)的宝贵知识。

本文目录一览:

在我的应用程序中在哪里打开和在哪里关闭SessionFactory(我的应用开启)

在我的应用程序中在哪里打开和在哪里关闭SessionFactory(我的应用开启)

我正在开发jsf应用程序,并使用hibernate模式作为后端。我想创建会话工厂,并在整个应用程序中关闭它。我正在使用util类创建Session工厂。

import org.hibernate.HibernateException;import org.hibernate.SessionFactory;import org.hibernate.cfg.Configuration;import org.hibernate.service.ServiceRegistry;import org.hibernate.service.ServiceRegistryBuilder;public class HibernateUtil{private static SessionFactory sessionFactory;private static ServiceRegistry serviceRegistry;static{    try    {        Configuration configuration = new Configuration().configure();        serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();        sessionFactory = configuration.buildSessionFactory(serviceRegistry);    }    catch (HibernateException he)    {        System.err.println("Error creating Session: " + he);        throw new ExceptionInInitializerError(he);    }}public static SessionFactory getSessionFactory(){    return sessionFactory;} } public static void closeFactory() {    if (sessionFactory != null) {        try {            sessionFactory.close();        } catch (HibernateException ignored) {            log.error("Couldn''t close SessionFactory", ignored);        }    }}

在我的DAO类的每种方法中,我都会打开会话工厂并关闭它。因此,在我只能打开/关闭会话工厂一次的应用程序中。提前致谢。

答案1

小编典典

在我的应用程序中在哪里打开和在哪里关闭SessionFactory

您正在使用单例会话工厂对象。因此,您可以使用类名称调用getSessionFactory()方法。因此您确实需要每次为会话工厂创建对象。

您的DAO类方法应如下所示

DAO类中的方法

public boolean createUser(NewUserDTO newUserDTO) {    try {        sessionFactory = DBUtils.getSessionFactory();        session = sessionFactory.openSession();        transaction = session.beginTransaction();        session.save(newUserDTO);        session.getTransaction().commit();    } catch (RuntimeException runtimeException) {        LOGGER.error(runtimeException);        transaction.rollback();        return false;    } finally {        if (session != null) {            session.close();        }    }    return true;}

并且必须为每种方法关闭会话。这样就不会为每个类都创建会话工厂。

Android ActionBar /工具栏消失在我的应用程序中

Android ActionBar /工具栏消失在我的应用程序中

所以我有一个应用程序.目前有3个活动…我正在用意图从另一个活动中启动活动

MainActivity > ChallongeLogin > ChallongeEvents

在我的MainActivity和ChallongeLogin中,应用程序顶部有一个大栏,列出了我的应用程序名称.但是,当我最终阅读ChallongeEvents时,该条消失了……我不记得做任何特别的事情使该条消失了.为什么消失了?

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.testing.testingapp">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity
            android:screenorientation="portrait"
            android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:screenorientation="portrait"
            android:name=".ChallongeLogin" />

        <activity
            android:screenorientation="portrait"
            android:name=".ChallongeEvents" />

    </application>

</manifest>

解决方法:

根据您的要求,您必须扩展AppCompatActivity而不是Activity.

public class ActivityName extends AppCompatActivity {
  // ...
}

AppCompatActivity is from the appcompat-v7 library. Principally, this
offers a backport of the action bar. Since the native action bar was
added in API Level 11, you do not need AppCompatActivity for that.
However, current versions of appcompat-v7 also add a limited backport
of the Material Design aesthetic, in terms of the action bar and
varIoUs widgets. There are pros and cons of using appcompat-v7, well
beyond the scope of this specific Stack Overflow answer.

参考

07001

extjs 应用程序中的 scss 文件在哪里

extjs 应用程序中的 scss 文件在哪里

我的猜测是这个类没有定义。此类只是添加到小部件元素。它不一定需要定义,当然在这种情况下它什么都不做。

如果你有一个名为 App.view.MyClass.js 的 Extjs 类定义(不是 css 类)这个文件应该在你的应用程序目录中的 view/MyClass.js 中,你可以创建一个名为 view/MyClass.scss 的 scss 文件和 sencha 命令将处理这个文件。默认的 app.json 告诉 sencha 命令寻找这个文件。

您可以在 development/{YOURAPPNAME}/resources 下的 build 文件夹中查看已编译的 scss 文件。这些文件将是 {YOURAPPNAME}-all_[1234...etc].css 如果你定义一个类,那么它应该在这些文件中,它会告诉你它是在哪个文件中定义的。

/* /u/xxx/work/temp/dcs3/webapp/erp/ws/packages/local/dcs/src/Dcs/view/util/ColoredCircleAvatar.scss:29 */
.circleavatar > img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

Hibernate 4.0.0Final在哪里,SessionFactory.openSession(拦截器拦截器)

Hibernate 4.0.0Final在哪里,SessionFactory.openSession(拦截器拦截器)

我尝试了一些来自hibernate
4.0拦截器的代码,该代码为使用会话级拦截器提供了以下代码:

Session session = sf.openSession( new AuditInterceptor() );

但是,我同时检查了hibernate-core 4.0源代码和onliehibernate 4.0 java-
doc,该类SessionFactory没有方法openSession(Interceptorinterceptor),但是hibernate 3.6 java-
doc确实具有此方法。

有人知道该方法移到哪里吗?如果已弃用,为什么文档仍将其保留在教程文档中?在4.0中如何使用会话级拦截器?

答案1

小编典典

现在使用Builder模式实现:

Session session = sf.withOptions()                    .interceptor(new AuditInterceptor())                    .openSession();

Hibernate 4中的SessionFactory.openSession(Connection)

Hibernate 4中的SessionFactory.openSession(Connection)

我正在使用抽送现有的JDBC连接SessionFactory.openSession(Connection)。现在在4.0中,此方法不可用。我应该使用哪种方法?

答案1

小编典典

您可以使用SessionFactory.withOptions()和SessionBuilder.connection(Connection
connection)。

SessionBuilder连接(连接连接)

将特定的连接添加到会话选项

参数connection- 要使用的连接。

返回 :此,用于方法链接

例:

SessionBuilder sb = SessionFactory.withOptions();Session session = sb.connection(connection).openSession();

关于在我的应用程序中在哪里打开和在哪里关闭SessionFactory我的应用开启的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Android ActionBar /工具栏消失在我的应用程序中、extjs 应用程序中的 scss 文件在哪里、Hibernate 4.0.0Final在哪里,SessionFactory.openSession(拦截器拦截器)、Hibernate 4中的SessionFactory.openSession(Connection)等相关知识的信息别忘了在本站进行查找喔。

本文标签: