Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java WebSphere未找到查询类的持久类_Java_Hibernate_Websphere_Environment_Entitymanager - Fatal编程技术网

Java WebSphere未找到查询类的持久类

Java WebSphere未找到查询类的持久类,java,hibernate,websphere,environment,entitymanager,Java,Hibernate,Websphere,Environment,Entitymanager,我是WebSphere的新手,正在尝试托管一个简单的网站,我可以使用Oracle数据库登录该网站 我可以访问我的网站,但当我尝试登录时,我收到以下警告,无法登录: [WARNING ] Detected JSESSIONID with invalid length; expected length of 23, found 28, setting: 99D3CCB2FF585D3B3E80293BFA1C to null. [WARNING ] HHH000183: no persistent

我是WebSphere的新手,正在尝试托管一个简单的网站,我可以使用Oracle数据库登录该网站

我可以访问我的网站,但当我尝试登录时,我收到以下警告,无法登录:

[WARNING ] Detected JSESSIONID with invalid length; expected length of 23, found 28, setting: 99D3CCB2FF585D3B3E80293BFA1C to null.
[WARNING ] HHH000183: no persistent classes found for query class: select a FROM com.model.User a where username = 'user'
 No entity found for query
当我尝试创建查询以登录到我的CommonServiceImple.java内部时,将抛出警告
找不到查询类:
Query Query=getEntityManager().createQuery(“从“+className+”中选择一个,其中username=”“+username+””)

试图运行查询的下一行中出现了未找到查询实体的
。这是因为前面的警告导致
query
对象为空:
objectobj=query.getSingleResult()

server.xml

<dataSource id="jdbc/test" jndiName="jdbc/test" type="javax.sql.DataSource">
    <jdbcDriver id="oracle-driver" libraryRef="oracle-lib">
        <library></library>
    </jdbcDriver>
    <connectionManager id="ConnectionManager" minPoolSize="1" numConnectionsPerThreadLocal="10"/>
    <properties.oracle URL="jdbc:oracle:thin:@crappie.ddvc.local:1521:STILOG" password="password" user="user"/>
</dataSource>
<library id="oracle-lib">
    <fileset dir="C:/Users/user/workspace/WebAdmin/WebContent/WEB-INF/lib/" includes="ojdbc6.jar"/>
</library>
<server description="new server">

    <!-- Enable features -->
    <featureManager>
        <feature>jsp-2.2</feature>
        <feature>jndi-1.0</feature>
        <feature>jdbc-4.0</feature>
        <feature>localConnector-1.0</feature>
        <feature>servlet-3.0</feature>
        <feature>jaxrs-1.1</feature>
    </featureManager>

    <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
    <httpEndpoint host="localhost" httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>

    <dataSource id="jdbc/test" jndiName="jdbc/test" type="javax.sql.DataSource">
        <jdbcDriver id="oracle-driver" libraryRef="oracle-lib"/>
        <connectionManager id="ConnectionManager" minPoolSize="1" numConnectionsPerThreadLocal="10"/>
        <properties.oracle URL="jdbc:oracle:thin:@crappie.local:1521:STILOG" password="password" user="user"/>
    </dataSource>

    <library id="oracle-lib">
        <fileset dir="C:/Users/user/workspace/WebAdmin/WebContent/WEB-INF/lib/" includes="ojdbc6.jar"/>
    </library>


    <applicationMonitor updateTrigger="mbean"/>

    <webApplication id="WebAdmin" location="WebAdmin.war" name="WebAdmin"/>

    <httpSession idLength="28"></httpSession>
</server>
或者是com服务impl.java

@Transactional
public class CommonServiceImpl implements CommonService{
    private EntityManager em;

    @PersistenceContext(unitName="pu1")
    public void setEntityManager(EntityManager em) {
        this.em = em;
    }

    // MTD added for explicit order by
    @SuppressWarnings("unchecked")
    public List<Object> findAll(String name) {
        getEntityManager().clear();
        String sql = "select a FROM " + name + " a";

        Query query = getEntityManager().createQuery(sql);

        return query.getResultList();
    }
//...(other sql selects, updates, inserts)
}
更新

我可以通过手动调用查找来测试与数据源的连接。但由于我的网站是建立在持久性单元上的,我希望修复该错误,而不是像这样重新编写项目以直接调用连接:

public String getEnvironment() {
    try
    {
        Context initCtx = new InitialContext();
        Context envCtx = (Context) initCtx.lookup("java:comp/env");
        DataSource test = (DataSource)envCtx.lookup("jdbc/test");

        Connection con = test.getConnection();
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("select * from WEB_PAGE_USERS where username = 'user'");

        while(rs.next()){
            System.out.println("username="+rs.getString("username")+", password="+rs.getString("password")+", role id="+rs.getString("role_id"));
        }

        //            environment = "[" + (String)envCtx.lookup("Environment") + "]";
    } catch (Exception e)
    {
        System.out.println("Environment Exception: " + e.getMessage());
    }
    return environment;
}

它确实返回了正确的数据
username=user,password=password,role id=1

要修复我的答案,我必须将带有@Entity注释的每个模型类添加到persistence.xml文件中。看起来,即使使用entityManager,我仍然需要指定所有@Entity类(通常在Tomcat中,entityManager会自动查找所有类)

我还发现
[WARNING]检测到的JSESSIONID长度无效;预期长度为23,发现长度为28,将:99D3CCB2FF585D3B3E80293BFA1C设置为null。
警告导致每次加载页面时清除我的会话(使我很难保持登录状态)。因此,我在WebSphere上的server.xml中将长度增加到28

server.xml

<dataSource id="jdbc/test" jndiName="jdbc/test" type="javax.sql.DataSource">
    <jdbcDriver id="oracle-driver" libraryRef="oracle-lib">
        <library></library>
    </jdbcDriver>
    <connectionManager id="ConnectionManager" minPoolSize="1" numConnectionsPerThreadLocal="10"/>
    <properties.oracle URL="jdbc:oracle:thin:@crappie.ddvc.local:1521:STILOG" password="password" user="user"/>
</dataSource>
<library id="oracle-lib">
    <fileset dir="C:/Users/user/workspace/WebAdmin/WebContent/WEB-INF/lib/" includes="ojdbc6.jar"/>
</library>
<server description="new server">

    <!-- Enable features -->
    <featureManager>
        <feature>jsp-2.2</feature>
        <feature>jndi-1.0</feature>
        <feature>jdbc-4.0</feature>
        <feature>localConnector-1.0</feature>
        <feature>servlet-3.0</feature>
        <feature>jaxrs-1.1</feature>
    </featureManager>

    <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
    <httpEndpoint host="localhost" httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>

    <dataSource id="jdbc/test" jndiName="jdbc/test" type="javax.sql.DataSource">
        <jdbcDriver id="oracle-driver" libraryRef="oracle-lib"/>
        <connectionManager id="ConnectionManager" minPoolSize="1" numConnectionsPerThreadLocal="10"/>
        <properties.oracle URL="jdbc:oracle:thin:@crappie.local:1521:STILOG" password="password" user="user"/>
    </dataSource>

    <library id="oracle-lib">
        <fileset dir="C:/Users/user/workspace/WebAdmin/WebContent/WEB-INF/lib/" includes="ojdbc6.jar"/>
    </library>


    <applicationMonitor updateTrigger="mbean"/>

    <webApplication id="WebAdmin" location="WebAdmin.war" name="WebAdmin"/>

    <httpSession idLength="28"></httpSession>
</server>

jsp-2.2
jndi-1.0
jdbc-4.0
localConnector-1.0
servlet-3.0
jaxrs-1.1
persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
    version="1.0">
    <persistence-unit name="pu1">  
    </persistence-unit>
</persistence>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
    version="1.0">
    <persistence-unit name="pu1">
        <class>com.model.App</class>
        <class>com.model.AudioType</class>
        <class>com.model.AuditRevisionEntity</class>
        <class>com.model.ClosedGroup</class>
        <class>com.model.ClosedSchedule</class>
        <class>com.model.ClosedScheduleGroup</class>
        <class>com.model.Department</class>
        <class>com.model.Dnis</class>
        <class>com.model.DnisVoiceTalent</class>
        <class>com.model.GlobalXferGroupTemplate</class>
        <class>com.model.Language</class>
        <class>com.model.Location</class>
        <class>com.model.MainMenu</class>
        <class>com.model.NameValue</class>
        <class>com.model.NameValueFunction</class>
        <class>com.model.NameValueType</class>
        <class>com.model.Peg</class>
        <class>com.model.PegType</class>
        <class>com.model.PharmacyConfig</class>
        <class>com.model.Promo</class>
        <class>com.model.PromoMessage</class>
        <class>com.model.PromoSchedule</class>
        <class>com.model.PromoType</class>
        <class>com.model.Role</class>
        <class>com.model.Schedule</class>
        <class>com.model.ScheduleHours</class>
        <class>com.model.ScheduleRecording</class>
        <class>com.model.ScheduleType</class>
        <class>com.model.Server</class>
        <class>com.model.SpecialSchedule</class>
        <class>com.model.SpecialScheduleRecording</class>
        <class>com.model.Store</class>
        <class>com.model.StoreAudio</class>
        <class>com.model.StoreClosedGroup</class>
        <class>com.model.StoreDepartment</class>
        <class>com.model.StorePromo</class>
        <class>com.model.StoreSchedule</class>
        <class>com.model.StoreSpcSchedule</class>
        <class>com.model.StoreType</class>
        <class>com.model.StoreXferGroup</class>
        <class>com.model.SystemMaintenance</class>
        <class>com.model.TargetSystem</class>
        <class>com.model.Timezone</class>
        <class>com.model.Title</class>
        <class>com.model.User</class>
        <class>com.model.UserWebPage</class>
        <class>com.model.UserWebPageAccess</class>
        <class>com.model.UserWebPageClassType</class>
        <class>com.model.VoiceTalent</class>
    </persistence-unit>
</persistence>

com.model.App
com.model.AudioType
com.model.AuditRevisionEntity
com.model.ClosedGroup
com.model.ClosedSchedule
com.model.ClosedScheduleGroup
模型部
com.model.Dnis
com.model.DnisVoiceTalent
com.model.GlobalXferGroupTemplate
com.model.Language
com.model.Location
com.model.main菜单
com.model.NameValue
com.model.NameValueFunction
com.model.NameValueType
com.model.Peg
com.model.PegType
com.model.PharmacyConfig
com.model.Promo
com.model.PromoMessage
com.model.PromoSchedule
com.model.PromoType
com.model.Role
com.model.Schedule
com.model.ScheduleHours
com.model.ScheduleRecording
com.model.ScheduleType
com.model.Server
com.model.SpecialSchedule
com.model.SpecialScheduleRecording
com.model.Store
com.model.StoreAudio
com.model.StoreClosedGroup
com.model.StoreDepartment
com.model.StorePromo
com.model.StoreSchedule
com.model.StoreSpcSchedule
com.model.StoreType
com.model.StoreXferGroup
com.model.SystemMaintenance
com.model.TargetSystem
时区
com.model.Title
com.model.User
com.model.UserWebPage
com.model.UserWebPageAccess
com.model.UserWebPageClassType
com.model.VoiceTalent

您知道为什么要进行
java:comp/env/Environment
查找,或者该位置应该包含什么吗?我所知道的是,当我尝试执行sql查询时,
找不到用于查询的实体。
java:comp/env/Environment
在我的操作失败后发生。我的服务/实体管理器似乎没有正确设置,但我不确定如何设置。我已经在主要问题中添加了登录操作。找到了调用java:comp/env/Environment的原因,以及它与查询类的
未找到持久性类无关:…
public String getEnvironment() {
    try
    {
        Context initCtx = new InitialContext();
        Context envCtx = (Context) initCtx.lookup("java:comp/env");
        DataSource test = (DataSource)envCtx.lookup("jdbc/test");

        Connection con = test.getConnection();
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("select * from WEB_PAGE_USERS where username = 'user'");

        while(rs.next()){
            System.out.println("username="+rs.getString("username")+", password="+rs.getString("password")+", role id="+rs.getString("role_id"));
        }

        //            environment = "[" + (String)envCtx.lookup("Environment") + "]";
    } catch (Exception e)
    {
        System.out.println("Environment Exception: " + e.getMessage());
    }
    return environment;
}
<server description="new server">

    <!-- Enable features -->
    <featureManager>
        <feature>jsp-2.2</feature>
        <feature>jndi-1.0</feature>
        <feature>jdbc-4.0</feature>
        <feature>localConnector-1.0</feature>
        <feature>servlet-3.0</feature>
        <feature>jaxrs-1.1</feature>
    </featureManager>

    <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
    <httpEndpoint host="localhost" httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>

    <dataSource id="jdbc/test" jndiName="jdbc/test" type="javax.sql.DataSource">
        <jdbcDriver id="oracle-driver" libraryRef="oracle-lib"/>
        <connectionManager id="ConnectionManager" minPoolSize="1" numConnectionsPerThreadLocal="10"/>
        <properties.oracle URL="jdbc:oracle:thin:@crappie.local:1521:STILOG" password="password" user="user"/>
    </dataSource>

    <library id="oracle-lib">
        <fileset dir="C:/Users/user/workspace/WebAdmin/WebContent/WEB-INF/lib/" includes="ojdbc6.jar"/>
    </library>


    <applicationMonitor updateTrigger="mbean"/>

    <webApplication id="WebAdmin" location="WebAdmin.war" name="WebAdmin"/>

    <httpSession idLength="28"></httpSession>
</server>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
    version="1.0">
    <persistence-unit name="pu1">
        <class>com.model.App</class>
        <class>com.model.AudioType</class>
        <class>com.model.AuditRevisionEntity</class>
        <class>com.model.ClosedGroup</class>
        <class>com.model.ClosedSchedule</class>
        <class>com.model.ClosedScheduleGroup</class>
        <class>com.model.Department</class>
        <class>com.model.Dnis</class>
        <class>com.model.DnisVoiceTalent</class>
        <class>com.model.GlobalXferGroupTemplate</class>
        <class>com.model.Language</class>
        <class>com.model.Location</class>
        <class>com.model.MainMenu</class>
        <class>com.model.NameValue</class>
        <class>com.model.NameValueFunction</class>
        <class>com.model.NameValueType</class>
        <class>com.model.Peg</class>
        <class>com.model.PegType</class>
        <class>com.model.PharmacyConfig</class>
        <class>com.model.Promo</class>
        <class>com.model.PromoMessage</class>
        <class>com.model.PromoSchedule</class>
        <class>com.model.PromoType</class>
        <class>com.model.Role</class>
        <class>com.model.Schedule</class>
        <class>com.model.ScheduleHours</class>
        <class>com.model.ScheduleRecording</class>
        <class>com.model.ScheduleType</class>
        <class>com.model.Server</class>
        <class>com.model.SpecialSchedule</class>
        <class>com.model.SpecialScheduleRecording</class>
        <class>com.model.Store</class>
        <class>com.model.StoreAudio</class>
        <class>com.model.StoreClosedGroup</class>
        <class>com.model.StoreDepartment</class>
        <class>com.model.StorePromo</class>
        <class>com.model.StoreSchedule</class>
        <class>com.model.StoreSpcSchedule</class>
        <class>com.model.StoreType</class>
        <class>com.model.StoreXferGroup</class>
        <class>com.model.SystemMaintenance</class>
        <class>com.model.TargetSystem</class>
        <class>com.model.Timezone</class>
        <class>com.model.Title</class>
        <class>com.model.User</class>
        <class>com.model.UserWebPage</class>
        <class>com.model.UserWebPageAccess</class>
        <class>com.model.UserWebPageClassType</class>
        <class>com.model.VoiceTalent</class>
    </persistence-unit>
</persistence>