-->
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.  [ 2 posts ] 
Author Message
 Post subject: <Table> is not mapped
PostPosted: Sun Dec 13, 2009 11:30 am 
Newbie

Joined: Sun Dec 13, 2009 11:19 am
Posts: 1
Hi@all
Ich muss mich ein wenig in hibernate einarbeiten und habe jetzt das Problem, dass ich die oben genannte Fehlermeldung erhalte.
Ich habe mich schon überall durchgelesen worauf der Fehler beruhen könnte und die einzige antwort die ich erhalten habe ist, dass ich die Query nicht auf die Tabelle sondern die Klasse ausführen soll, aber genau das tu ich und erhalte trotztdem den fehler


Meine Main
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package hibernatetest;

import SessionFactory.SessionFactory;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;


/**
*
* @author TJay
*/
public class Main {
//private static org.hibernate.SessionFactory sessionFactory;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here


        Session session = (Session) SessionFactory.getInstance().getCurrentSession();
       
        Transaction tx = session.beginTransaction(); 
        Query query = session.createQuery("from Departments");
        tx.commit();

    }
}



Die SessionFactory
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package SessionFactory;

import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;

/**
*
* @author TJay
*/
public class SessionFactory {

    private static org.hibernate.SessionFactory sessionFactory;

    private SessionFactory() {
    }

    static {

        //final Configuration cfg = new Configuration();
        final AnnotationConfiguration cfg = new AnnotationConfiguration();


        /*
         * configure Hibernate from hibernate.cfg.xml. This is expected to be in
         * the class path = "src folder" = "root folder of classes"
         */
        cfg.configure("/hibernate.cfg.xml");
        cfg.buildSessionFactory();
        sessionFactory = cfg.buildSessionFactory();
        sessionFactory.openSession();


    }

    /**
     * Returns the single instance of the session factory
     *
     * @return
     */
    public static org.hibernate.SessionFactory getInstance() {
        return sessionFactory;
    }
}


Meine Klasse
Code:
package Tables;
// Generated 13.12.2009 03:40:34 by Hibernate Tools 3.2.1.GA


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

/**
* Departments generated by hbm2java
*/
@Entity
@Table(name="DEPARTMENTS"
    ,schema="ADMIN"
)
public class Departments  implements java.io.Serializable {


     private short departmentId;
     private String departmentName;
     private Integer managerId;
     private Short locationId;

    public Departments() {
    }

   
    public Departments(short departmentId, String departmentName) {
        this.departmentId = departmentId;
        this.departmentName = departmentName;
    }
    public Departments(short departmentId, String departmentName, Integer managerId, Short locationId) {
       this.departmentId = departmentId;
       this.departmentName = departmentName;
       this.managerId = managerId;
       this.locationId = locationId;
    }
   
     @Id
   
    @Column(name="DEPARTMENT_ID", unique=true, nullable=false, precision=4, scale=0)
    public short getDepartmentId() {
        return this.departmentId;
    }
   
    public void setDepartmentId(short departmentId) {
        this.departmentId = departmentId;
    }
   
    @Column(name="DEPARTMENT_NAME", nullable=false, length=30)
    public String getDepartmentName() {
        return this.departmentName;
    }
   
    public void setDepartmentName(String departmentName) {
        this.departmentName = departmentName;
    }
   
    @Column(name="MANAGER_ID", precision=6, scale=0)
    public Integer getManagerId() {
        return this.managerId;
    }
   
    public void setManagerId(Integer managerId) {
        this.managerId = managerId;
    }
   
    @Column(name="LOCATION_ID", precision=4, scale=0)
    public Short getLocationId() {
        return this.locationId;
    }
   
    public void setLocationId(Short locationId) {
        this.locationId = locationId;
    }




}




Meine "hibernate.cfg.xml
Code:
<?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">
<hibernate-configuration>
  <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
        <property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:admin/admin@localhost:1521:XE</property>
        <property name="hibernate.connection.username">admin</property>
        <property name="hibernate.connection.password">admin</property>

        <!-- -->
        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>


        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">update</property>




        </session-factory>
</hibernate-configuration>



Und hier noch mal meine Fehlermeldung
Code:
run:
13.12.2009 16:30:25 org.hibernate.cfg.annotations.Version <clinit>
INFO: Hibernate Annotations 3.3.1.GA
13.12.2009 16:30:25 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.5
13.12.2009 16:30:25 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
13.12.2009 16:30:25 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
13.12.2009 16:30:25 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
13.12.2009 16:30:25 org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
13.12.2009 16:30:25 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
13.12.2009 16:30:25 org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
13.12.2009 16:30:25 org.hibernate.cfg.AnnotationConfiguration secondPassCompile
INFO: Hibernate Validator not found: ignoring
13.12.2009 16:30:25 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
13.12.2009 16:30:25 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
13.12.2009 16:30:25 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
13.12.2009 16:30:25 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: oracle.jdbc.OracleDriver at URL: jdbc:oracle:thin:admin/admin@localhost:1521:XE
13.12.2009 16:30:25 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=admin, password=****}
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Oracle, version: Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: Oracle JDBC driver, version: 9.2.0.1.0
13.12.2009 16:30:26 org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.Oracle10gDialect
13.12.2009 16:30:26 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
13.12.2009 16:30:26 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
13.12.2009 16:30:26 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
13.12.2009 16:30:26 org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
13.12.2009 16:30:26 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
13.12.2009 16:30:26 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: Running hbm2ddl schema update
13.12.2009 16:30:26 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: fetching database metadata
13.12.2009 16:30:26 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: updating schema
13.12.2009 16:30:26 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: schema update complete
13.12.2009 16:30:26 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
13.12.2009 16:30:26 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
13.12.2009 16:30:26 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
13.12.2009 16:30:26 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: oracle.jdbc.OracleDriver at URL: jdbc:oracle:thin:admin/admin@localhost:1521:XE
13.12.2009 16:30:26 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=admin, password=****}
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Oracle, version: Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: Oracle JDBC driver, version: 9.2.0.1.0
13.12.2009 16:30:26 org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.Oracle10gDialect
13.12.2009 16:30:26 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
13.12.2009 16:30:26 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
13.12.2009 16:30:26 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
13.12.2009 16:30:27 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
13.12.2009 16:30:27 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
13.12.2009 16:30:27 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
13.12.2009 16:30:27 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
13.12.2009 16:30:27 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
13.12.2009 16:30:27 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
13.12.2009 16:30:27 org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
13.12.2009 16:30:27 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
13.12.2009 16:30:27 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
13.12.2009 16:30:27 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
13.12.2009 16:30:27 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
13.12.2009 16:30:27 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
13.12.2009 16:30:27 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
13.12.2009 16:30:27 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
13.12.2009 16:30:27 org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
13.12.2009 16:30:27 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
13.12.2009 16:30:27 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: Running hbm2ddl schema update
13.12.2009 16:30:27 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: fetching database metadata
13.12.2009 16:30:27 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: updating schema
13.12.2009 16:30:27 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: schema update complete
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: Departments is not mapped [from Departments]
        at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
        at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
        at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
        at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:255)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
        at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
        at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
        at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
        at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
        at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
        at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
        at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
        at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
        at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
        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:597)
        at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
        at $Proxy0.createQuery(Unknown Source)
        at hibernatetest.Main.main(Main.java:30)
Java Result: 1
BUILD SUCCESSFUL (total time: 3 seconds)


Top
 Profile  
 
 Post subject: Re: <Table> is not mapped
PostPosted: Mon Dec 14, 2009 3:09 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
Du musst die gemappten Klassen auch der Konfiguration bekannt machen. Dazu fügst du in die hibernate.cfg.xml folgendes ein:

<mapping class="Tables.Departments" />

Wobei Grossbuchstaben am Anfang von Packakenamen bäh sind...


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