[Hibernate-JIRA] Created: (HSEARCH-349) Allow custom Loader in FullTextQueryImpl
by Julien Kronegg (JIRA)
Allow custom Loader in FullTextQueryImpl
----------------------------------------
Key: HSEARCH-349
URL: http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-349
Project: Hibernate Search
Issue Type: New Feature
Components: query
Affects Versions: 3.1.0.GA
Environment: Hibernate 3.3.1.GA, DB2
Reporter: Julien Kronegg
Priority: Minor
When doing an native SQL query containing join and other complicated stuff, one can get a List<MyObject> using the following code:
List<MyObject> list = entityManager.createNativeQuery("SELECT ...", MyObject.class).getResultList();
The MyObject class is an JPA Entity, but is not connected to a database table: the MyObject instance is reconstructed automatically by mapping the ResultSet column names and the MyObject field names.
This object list can be indexed using Hibernate Search (by adding @Indexed and @Field annotations to the MyObject entity). When doing an Hibernate Search query, the FullTextQueryImpl.list() method uses a Loader which try to load the MyObject entities from the database by a query such as "SELECT ... FROM MYOBJECT where id in (?,?,?,..)" (where the list of "?" is the list of identifiers returned by Lucene).
Here, we have a problem: the MYOBJECT table does not exist and obviously an exception is raised. The desired result would be for example to look into the initial List<MyObject> "list" instead of asking to the database.
This functionnality could be done very simply by adding a "Loader customLoader" field (with its public getter/setter) in the org.hibernate.search.query.FullTextQueryImpl class and by modifying the getLoader() method such as:
private Loader getLoader(Session session, SessionFactoryImplementor sessionFactoryImplementor) {
if (customLoader!=null) {
customLoader.init(session, sessionFactoryImplementor);
return customLoader;
}
...
}
After this modification, the programmer can design its own Loader which implements whatever loading strategy. For the example above, the Loader.load(EntityInfo[]) method may looks for each EntityInfo.id in the initially obtained List<MyObject> "list".
There is a workaround: copy the full source code of FullTextQueryImpl and add the described modifications.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
13 years
[Hibernate-JIRA] Created: (HHH-5308) hibernate cannot handle Inheritance, if the discriminatorColumn is part of a composite pk in a @MappedSupperclass
by AndyW (JIRA)
hibernate cannot handle Inheritance, if the discriminatorColumn is part of a composite pk in a @MappedSupperclass
-----------------------------------------------------------------------------------------------------------------
Key: HHH-5308
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5308
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.5.2
Environment: Linux, Java 6
Reporter: AndyW
Attachments: jpatest_hibernate_aktuell.zip
Hi,
i am having the following mapping structure
@MappedSuperclass
LadeeinheitEinausgaenge
| @Entity
| @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
| @DiscriminatorColumn(name = "LAEA_TYP")
| @Table(name = "LADEEINHEIT_EINAUS")
+- AbstractEinAusgang
| | @DiscriminatorValue("AUSGANG")
| | @Entity
| +- LadeeinheitAusgaenge
| | @DiscriminatorValue("EINGANG")
| | @Entity
| +- LadeeinheitEingaenge
The composite pk is defined in the MappedSuperclass. The discriminator column
is part of the composite pk. when i start my app, i am getting the following error:
> Repeated column in mapping for entity: de.dbsystel.gate.integration.model.LadeeinheitAusgaenge column: LAEA_TYP (should be mapped with insert="false" update="false")
the error message is kind of misleading, because the @DiscriminatorColumn annotation only defines which column to use for the mapping, i guess. however the actual mapping is defined in the MappedSuperclass.
When moving the @DiscriminatorColumn to the mappedSuperclass, hibernate does not complain when starting,
but then it creates tables, it create the default DiscriminatorColumn named DTYPE, which is not wanted, because i explicitly defined a discriminator column. If the discriminator column is defined in the mappedSuperclass then it will be ignore. if it is defined in my abstract base entity. then i get the error mentioned above.
My Intention is to query the AbstractEinAusgang and get one of the two possible concrete
classes, that are defined via the discriminator value.
i have attached the testcase that shows the problem.
cheers,
andy
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
13 years