JPA Unknown SqlResultSetMapping when several persistence unit - java

I am trying to map the result of a stored procedure to an entity list and I am guided by the following post https://www.baeldung.com/jpa-sql-resultset-mapping .
Now I am having the next error:
org.hibernate.procedure.UnknownSqlResultSetMappingException: The given
SqlResultSetMapping name [Unknown SqlResultSetMapping [Foo]] is
unknown
I suspect that the problem could be that I am working with several databases in my project.
How could I specify the context or persistence unit in which the resultMapping is?

Related

NamedNativeQuery throws PSQLException: ERROR: relation "mytable" does not exist [duplicate]

I have many EntityManager, one per schema that I have (I use entity-mappings file to map EMs with schemas). It works.
When I use #NamedQuery it's working like a charm but when I use #NamedNativeQuery schema is not used. I have to qualify with it SELECT foo FROM schema.table.
Is it the right behaviour ?
I think it's not possible to parameter #NamedNativeQuery to dynamically pass schema (I believe only columns can be dynamics not tables or schemas or anything else) so how can I use #NamedNativeQuery with dynamic schema please ?
Prefix your table name with "{h-schema}", e.g.SELECT foo FROM {h-schema}table
(courtesy of getting hibernate default schema name programmatically from session factory?)
Excerpts from documentation :
NamedNativeQuery : Specifies a named native SQL query. Query names are scoped to the persistence unit.
NamedQuery : Specifies a static, named query in the Java Persistence query language. Query names are scoped to the persistence unit.
It isn't specified directly that NamedNativeQuery is static, but both are same scoped & can't be altered afterwards & it's the desired behaviour.
Named queries are mean to be accessed by multiple modules - application wide, identified by unique name, so they are static & constant. You can try building a query string dynamically & can create a native query from it, instead of named native query.

Spring data cross-store with MongoDB and MySQL

I am trying to create a data access layer where an application would like to use both a traditional SQL store as well as a NoSQL store. After few searches, I have found a concept like Spring Data MongoDB cross strore and this concept similar to my requirement. So that, I have successfully configured as suggested in the reference document https://stackoverflow.com/a/13998825.
But I am getting below error when I test the above sample. Can some one please help in this regard...
Error: Caused by: org.hibernate.MappingException: Could not determine type for: com.hcc.riab.model.ProductInfo, at table: Product, for columns: [org.hibernate.mapping.Column(productInfo)]

How to instantiate the LAZY relationship prior to serialization?

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

JDBC Derby JPA Persistence testing issue "Internal Exception: java.sql.SQLSyntaxErrorException: Syntax error: Encountered 'USER'"

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).

How to generate POJO from PostgreSQl/PostGIS?

I have a 25 .xsd schemas and want to generate DB tables and POJO classes from this schemas.
Hibernate can do it? Im already try generate DB tables with XMLSpy and POJO with JiBX, but when i generate mapping with Hibernate names of tables in DB and in mappings was different. I want to use single tool to do this.
UPDATE
I try generate POJO with hibernate. I create \hibernate.cfg.xml ,hibernate.reveng.xml and console config. And when i try run configuration get error
org.hibernate.MappingException: Could not configure overrides from file: D:\liferay-develop\workspace\JABX_test\src\hibernate.reveng.xml
Could not configure overrides from file: D:\liferay-develop\workspace\JABX_test\src\hibernate.reveng.xml
org.hibernate.MappingException: invalid override definition
invalid override definition
org.hibernate.MappingException: invalid override definition
invalid override definition
org.xml.sax.SAXParseException: The content of element type "hibernate-reverse-engineering" must match "(schema-selection*,type-mapping?,table-filter*,table*)".
The content of element type "hibernate-reverse-engineering" must match "(schema-selection*,type-mapping?,table-filter*,table*)".
When i use empty TableFilter in reverse enginering hibernate create POJO but only from deafult postgres tables.
what i doing wrong?
UPDATE 2
How i use this tutorial http://www.youtube.com/watch?v=tfZiKn5xhXk and get error
org.hibernate.exception.JDBCConnectionException: Getting database metadata
Getting database metadata
java.sql.SQLException: No suitable driver found for jdbc:postgresql:localhost:5632:postgis_test
No suitable driver found for jdbc:postgresql:localhost:5632:postgis_test
java.sql.SQLException: No suitable driver found for jdbc:postgresql:localhost:5632:postgis_test
No suitable driver found for jdbc:postgresql:localhost:5632:postgis_test
UPDATE 3
Okey. Im reinstal eclipse and get situation like in first UPDATE again. So i try generate POJO from DB and get only POJO from postgis tables: geography_columns and spatial_ref_sys. Hibernate cant work with PostGis?

Categories

Resources