Hi don't understand the problem with namedQuery
<query name="updtae.payment.paymentDate.by.txn_id">
<![CDATA[
update Payment p set p.paymentDate =:payDate WHERE p.txnId=:txnId]]>
</query>
getting exception
HIbernate org.hibernate.HibernateException: Errors in named queries
no columns same us entity Name
It works fine in local And don't on production server
getSession().getNamedQuery("updtae.payment.paymentDate.by.txn_id").setTimestamp("payDate",paymentDate ).setString("txnId", txnId).executeUpdate();
Here is call of named query.
I fix problem buy changing hibernate version
from Hibernate-Version: 3.0.5
to Hibernate-Version: 3.2.1.ga
Related
I have the following jpa/hibernate/hsqldb configuration:
JPA ddl-auto: create-drop
Hibernate entities have no #Table annotation and created with SpringPhysicalNamingStrategy. So, PersonalData entity table name is personal_data. Hibernate creates them due to running the application
hsql DB URL is jdbc:hsqldb:mem:testdb;sql.syntax_pgs=true
My problem is when I try to select due spring repositories with the hsql there is the error about non-existing PERSONAL_DATA table.
I found that this is SQL notation to use CASE_SENSETIVE tables and hqsl follows that. To resolve that developers offer quote table names in sql.
So, I have 2 unlikely ideas
Add #Table annotation to entities.
Override SpringPhysicalNamingStrategy
Is there a way to use a simple property?
I'm getting an error which looks like:
java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: DirectAddress is not mapped [select d from DirectAddress d where emailaddress=?]
where query looks like
Query query = session.createQuery("select d from DirectAddress d where emailaddress=?");
and I have set an entity for javax
#Entity
#Table(name = "user")
Then I have tired that query:
Query query = session.createQuery("select d from " + DirectAddress.class.getName() + " d where emailaddress=?");
without any luck.
Also project is not using hibernate.cfg.xml file.
Any thoughts?
To use an entity you've created, make sure it's marked as #Entity using the javax library. You'll also need to map it so hibernate knows it's supposed to link it to your database table. Please verify if your entity is mapped in your applicationContext.xml (for spring applications) or persistence.xml in common hibernate applications.
Mapping your entities
You can map your entities in many ways. The most common methods are:
Mapping it directly in hibernate.cfg.xml:
<mapping class="your.packages.to.the.entity.class" />
Setting it up in your spring applicationContext.xml`s hibernate configurations
For a working example, please refer to:
How configure hibernate.cfg.xml to applicationContext.xml as dataSource?
By Spring Injection
You mentioned not using hibernate.cfg.xml. Are you injecting hibernate`s settings via spring (in a non-web application)? If so, please refer to Can we configure Hibernate Without hibernate.cfg.xml
If none of the solutions apply, please provide more details about your System (web, desktop, setting up hibernate programatically, etc) and i`ll edit with this answer with the most appropriate solution.
Cheers!
DirectAddress is not mapped [select d from DirectAddress d where emailaddress=?]
means hibernate did not find mapping for DirectAddress class.
Check persistence.xml file for entity mapping or you can directly add this class while initializing/loading Configuration.
I have just created and joined 3 new tables. Before creating them everything was working fine so I do believe the root cause is coming from their creation. Now when runned in the browser I receive this error:
org.apache.jasper.JasperException: Exception [EclipseLink-7242]
(Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd):
org.eclipse.persistence.exceptions.ValidationException
Exception Description: An attempt was made to traverse a relationship using indirection that had a null Session. This often
occurs when an entity with an uninstantiated LAZY relationship is
serialized and that lazy relationship is traversed after
serialization. To avoid this issue, instantiate the LAZY relationship
prior to serialization.
How does one instantiate the LAZY relationship prior to serialization anyway? I've been looking all over the web but I still haven't found real working solutions...
I also receive this other error message:
Exception [EclipseLink-4002] (Eclipse Persistence Services -
2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
Unknown column 't1.rating' in 'field list' Error Code: 1054 Call:
SELECT t1.id, t1.description, t1.last_update, t1.name, t1.price,
t1.rating FROM category_has_product t0, product t1 WHERE
((t0.category_id = ?) AND (t1.id = t0.product_id)) bind => [1
parameter bound] Query: ReadAllQuery(name="productCollection"
referenceClass=Product sql="SELECT t1.id, t1.description,
t1.last_update, t1.name, t1.price, t1.rating FROM category_has_product
t0, product t1 WHERE ((t0.category_id = ?) AND (t1.id =
t0.product_id))")
root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown
column 't1.rating' in 'field list'
What do all those errors mean? I don't understand because all the columns and the rows are perfectly well mapped... It says it canno't find certain columns... I have checked all my tables over and over and I really don't understand what could possibly be wrong... Everything seems fine... A little help would be very much appreciated! Thanks
Besides I use the following for the app:
Netbeans
Glassfish
Mysql
Most pages in jsp
Problem with instantiate lazy reference is well known, so I will provide a link rather than explain myself: http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Serialization.2C_and_Detaching
Wiki page has also 3 solutions to solve the problem. But I will offer you another solution, which may suits your case: JSP usage.
Check https://dzone.com/articles/open-session-view-design (or just google for 'open session in view'. Many pages refers to Hibernate but it applies to Eclipselink also). The solution is start and end transaction in servlet filter. The transaction will cover whole request processing. In your case JSP page generation will be within transaction and lazy references will just work. Benefit is that you don't have to modify your code.
I have no idea about your second problem with mapping
I have an entity class called User and when I do persistence testing with Arquillian I have always have an error...
Internal Exception: java.sql.SQLSyntaxErrorException: Syntax error: Encountered "USER" at line 1, column 13.
...because of the class name "User". I assume User is the reserved keyword. When I change my entity name to User_ it works fine.
Do I have to change my entity name? Is there anything else I can do to fix this issue?
Yes, USER is a built-in function in Derby. You'd have to specify a different table name for the JPA entity (usually done via the #Table annotation).
I just set up a basic hibernate/spring project to test some stuff. I use a MySQL db by using WAMP.
These are all of the classes: http://codepaste.net/7pwmtx
This is my bean definition and pom file: http://codepaste.net/4iz7jb
POM is a little bit messy but this is the problem: I think that I set up my dialect properly because I get no errors when i add something to the db. I get errors when I use find in hql. I t seems like hibernate isnt retrieving data from the same place that it is putting it. Any idea why this doesnt work?
By the way, the console output was:
Exception in thread "main" org.springframework.orm.hibernate3.HibernateQueryException: hobject is not mapped [from hobject]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: hobject is not mapped [from hobject]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:660)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:912)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:904)
at hibernate.dao.SpringHibernateOperatorImplementation.getAllRows(SpringHibernateOperatorImplementation.java:24)
at hibernate.main.HibernateMain.main(HibernateMain.java:22)
Caused by: org.hibernate.hql.ast.QuerySyntaxException: hobject is not mapped [from hobject]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:277)
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:251)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:134)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1650)
at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:914)
at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:1)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
... 5 more
Add the entity class hibernate.dao.HObject to hibernate.cfg.xml files. It is neeeded even if you are using annotation based configurations.
If you want to skip adding these to cfg file you can use the approach mentioned here provided you are using spring.