-->
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.  [ 7 posts ] 
Author Message
 Post subject: is not mapped?
PostPosted: Mon Aug 01, 2005 12:48 pm 
Newbie

Joined: Mon Aug 01, 2005 12:40 pm
Posts: 3
I am getting an error that my table in the database is not mapped. It is strange becuase I can see in the log that is is mapping the class to the table.

The tablename is "candidate" adn the class is "CandidateDTO"

here is the output to the log.

[exec] 12:32:48,443 INFO [Configuration] configuring from resource: /hibernate.cfg.xml
[exec] 12:32:48,443 INFO [Configuration] Configuration resource: /hibernate.cfg.xml
[exec] 12:32:48,693 INFO [Configuration] Mapping resource: com/csg/dto/CandidateDTO.hbm.xml
[exec] 12:32:49,955 INFO [HbmBinder] Mapping class: com.csg.dto.CandidateDTO -> candidate
[exec] 12:32:50,025 INFO [Configuration] Configured SessionFactory: null
[exec] 12:32:50,025 INFO [Configuration] processing extends queue
[exec] 12:32:50,025 INFO [Configuration] processing collection mappings
[exec] 12:32:50,025 INFO [Configuration] processing association property references
[exec] 12:32:50,025 INFO [Configuration] processing foreign key constraints
[exec] 12:32:50,276 INFO [NamingHelper] JNDI InitialContext properties:{}
[exec] 12:32:50,286 INFO [DatasourceConnectionProvider] Using datasource: java:MSSQLDS
[exec] 12:32:52,118 INFO [SettingsFactory] RDBMS: Microsoft SQL Server, version: Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
[exec] Dec 17 2002 14:22:05
[exec] Copyright (c) 1988-2003 Microsoft Corporation
[exec] Developer Edition on Windows NT 5.0 (Build 2195: Service Pack 4)
[exec] 12:32:52,118 INFO [SettingsFactory] JDBC driver: SQLServer, version: 2.2.0040
[exec] 12:32:52,198 INFO [Dialect] Using dialect: org.hibernate.dialect.SQLServerDialect
[exec] 12:32:52,249 INFO [TransactionFactoryFactory] Using default transaction strategy (direct JDBC transactions)
[exec] 12:32:52,259 INFO [TransactionManagerLookupFactory] No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
[exec] 12:32:52,259 INFO [SettingsFactory] Automatic flush during beforeCompletion(): disabled
[exec] 12:32:52,259 INFO [SettingsFactory] Automatic session close at end of transaction: disabled
[exec] 12:32:52,269 INFO [SettingsFactory] Scrollable result sets: enabled
[exec] 12:32:52,269 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): disabled
[exec] 12:32:52,269 INFO [SettingsFactory] Connection release mode: null
[exec] 12:32:52,269 INFO [SettingsFactory] Default batch fetch size: 1
[exec] 12:32:52,269 INFO [SettingsFactory] Generate SQL with comments: disabled
[exec] 12:32:52,269 INFO [SettingsFactory] Order SQL updates by primary key: disabled
[exec] 12:32:52,269 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
[exec] 12:32:52,309 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
[exec] 12:32:52,319 INFO [SettingsFactory] Query language substitutions: {}
[exec] 12:32:52,319 INFO [SettingsFactory] Second-level cache: enabled
[exec] 12:32:52,319 INFO [SettingsFactory] Query cache: disabled
[exec] 12:32:52,319 INFO [SettingsFactory] Cache provider: org.hibernate.cache.EhCacheProvider
[exec] 12:32:52,329 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
[exec] 12:32:52,339 INFO [SettingsFactory] Structured second-level cache entries: disabled
[exec] 12:32:52,369 INFO [SettingsFactory] Echoing all SQL to stdout
[exec] 12:32:52,369 INFO [SettingsFactory] Statistics: disabled
[exec] 12:32:52,369 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
[exec] 12:32:52,379 INFO [SettingsFactory] Default entity-mode: pojo
[exec] 12:32:52,799 INFO [SessionFactoryImpl] building session factory
[exec] 12:32:52,839 WARN [Configurator] No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Applications/jboss-4.0.2/server/default/tmp/deploy/tmp45759CATS-exp.war/WEB-INF/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
[exec] 12:32:53,881 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
[exec] 12:32:53,881 INFO [SessionFactoryImpl] Checking 0 named queries
[exec] 12:32:54,021 INFO [STDOUT] FROM candidate c where c.candidate_id = ?
[exec] 12:32:54,482 ERROR [PARSER] *** ERROR: candidate is not mapped.
[exec] 12:32:54,552 ERROR [PARSER] *** ERROR: Invalid path: 'c.candidate_id'
[exec] 12:32:54,552 ERROR [PARSER] *** ERROR: <AST>: unexpected end of subtree


I see the message:

[exec] 12:32:49,955 INFO [HbmBinder] Mapping class: com.csg.dto.CandidateDTO -> candidate

Which would appear that the mapping is created. Why is it complaining that the table is not mapped?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 1:06 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Please provide your query as well as the mapping for your class.

Best regards
Sven


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 1:18 pm 
Newbie

Joined: Mon Aug 01, 2005 12:40 pm
Posts: 3
Here is the contents of the mapping file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.csg.dto.CandidateDTO" table="candidate">
<id column="candidate_id" name="candidateId" type="java.lang.Integer">
<generator class="increment"/>
</id>
<property column="first_name" name="firstName" type="java.lang.String"/>
<property column="last_name" name="lastName" type="java.lang.String"/>
<property column="middle_initial" name="middleInitial" type="java.lang.String"/>
<property column="street_address" name="streetAddress" type="java.lang.String"/>
<property column="city" name="city" type="java.lang.String"/>
<property column="state" name="state" type="java.lang.String"/>
<property column="zip" name="zipCode" type="java.lang.String"/>
<property column="phone" name="phone" type="java.lang.String"/>
<property column="email" name="emailAddress" type="java.lang.String"/>
</class>
</hibernate-mapping>

and here is the code from the DAO.

public class CandidateDAO {

//Log4j logger
private static Logger logger = Logger.getLogger(HibernateUtils.class);

private String CANDIDATE_BY_ID_QUERY = "FROM candidate c where c.candidate_id = ?";

/**
* Empty constructor
*
*/
public CandidateDAO()
{
}

/**
* Get candidate by ID
* @param candidateId
* Int containing the id of the candidate to retrieve
* @return candidate
* @throws CatsException
*/
public CandidateDTO getCandidateById(int candidateId) throws CatsException
{
CandidateDTO candidate = null;
try{

Session session = HibernateUtils.currentSession();
Query query = session.createQuery(CANDIDATE_BY_ID_QUERY);
query.setInteger(0, candidateId);
System.out.println(query.getQueryString());
List list = query.list();

if(list.size() == 1)
{
candidate = (CandidateDTO)list.get(0);
}

}catch(Exception e){
throw new CatsException("Error retrieving candidate by ID",e);
}
return candidate;
}
}

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 1:27 pm 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
dsparks5 wrote:
private String CANDIDATE_BY_ID_QUERY = "FROM candidate c where c.candidate_id = ?";


... should be ...

Code:
private String CANDIDATE_BY_ID_QUERY = "FROM CandidateDTO c where c.candidate_id = ?";


If you turned off "auto-import" for some reason, then you'll need the package name in there too.

More details and examples here.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 1:27 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
dsparks5 wrote:
[...]
private String CANDIDATE_BY_ID_QUERY = "FROM candidate c where c.candidate_id = ?";

[...]
Query query = session.createQuery(CANDIDATE_BY_ID_QUERY);

This won't work. Have a look at the documentation (esp. chapter 15).
http://www.hibernate.org/hib_docs/v3/re ... /#queryhql
You cannot use pure SQL with session.createQuery(...).

In your case something like the following will work.
Code:
Query query = session.createQuery("from CandidateDTO as c where c.candidateId = :cid");
query.setInteger("cid", yourId);


Best regards
Sven


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 1:36 pm 
Newbie

Joined: Mon Aug 01, 2005 12:40 pm
Posts: 3
Thank you! It is working now. I guess I should have take mote time to read the documentation.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 1:40 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
dsparks5 wrote:
Thank you! It is working now. I guess I should have take mote time to read the documentation.


Exactly - as well as taken some time to rate our replies. ;)

Best regards
Sven


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.