How best to eliminate the Javassist dependency from Hibernate applications...
by Scott Marlow
As modular classloading environments become more popular (e.g. WildFly,
OSGi, Openjdk Jigsaw), it is more important that applications can
include their own version of Javassist classes. This is not possible if
the application classpath also needs to include the Hibernate (needed)
version of Javassist.
My question is how would/should this be accomplished? Some proposals
are below:
1. Clone the Javassist runtime classes into Hibernate ORM and maintain
them as a fork. I don't think this is practical but still wanted to
mention it as a possible solution.
2. Stop using the parts of the Javassist api that generate bytecode
that depends on the Javassist runtime classes. I have no idea how hard
this would be.
I don't think we have a jira for this yet, although we have talked about
it occasionally for years.
Any volunteers to help?
Scott
7 years, 3 months
Hibernate ORM FAQ in JBoss wiki
by Gunnar Morling
Vlad, all,
In the JBoss.org wiki there are several interesting FAQs around Hibernate ORM:
https://developer.jboss.org/en/hibernate/faq
They provide very useful info (just learned something new by reading
them), but since the last updated more than five years have passed. So
I suppose some stuff is outdated by now.
Assuming those contents are worth keeping, it would be great if they
could be revised, sorted out / updated as needed and moved over to
http://hibernate.org/orm/faq/ eventually.
Do you think you could take a look at these at some point? I know it's
fair bit of work, but the Hibernate community would be deeply grateful
to your forever :)
Cheers,
--Gunnar
7 years, 3 months
HHH-10500 and multiple associations using the same foreign key column
by Gail Badner
For joined inheritance, such as:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "task_base")
public class TaskBase { ... }
@Entity
@Table(name = "task")
public class Task extends TaskBase { ... }
Does JPA allow mapping a one-to-many association with the foreign key
column in a superclass table (task_base)? For example:
@Entity
public class Goal {
...
@OneToMany(targetEntity = TaskBase.class)
@JoinColumn(name = "goal_id", table = "task_base")
private Set<Task> tasks = new HashSet<Task>();
...
}
Currently, Hibernate throws: org.hibernate.cfg.NotYetImplementedException:
Collections having FK in secondary table.
As you can see. the foreign key is actually in the superclass table.
JPA 2.1 spec says this for the description of @JoinColumn( name="..." )
when used for a unidirectional one-to-many association:
"If the join is for a unidirectional OneToMany mapping using a foreign key
mapping strategy, the foreign key is in the table of the target entity."
Is "the table of the target entity" just a default that can be overridden
by the "table" attribute? If so, then this is a bug in Hibernate.
Another question, does JPA allow multiple associations to use the same
foreign key column? For example:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "task_base")
public class TaskBase { ... }
@Entity
@Table(name = "task")
public class Task extends TaskBase { ... }
@Entity
@Table(name = "othertask")
public class OtherTask extends TaskBase { ... }
@Entity
public class Goal {
...
@OneToMany
@JoinColumn(name = "goal_id", table = "task_base")
private Set<Task> tasks = new HashSet<Task>();
@OneToMany
@JoinColumn(name = "goal_id", table = "task_base")
private Set<OtherTask> otherTasks = new HashSet<OtherTask>();
...
}
The above also fails with NotYetImplementedException for the same reason.
I've created a pull request with this test case. [1]
When I switched to use single table inheritance, there was no failure, but
when Goal.tasks is loaded, it contained both Task and OtherTask objects.
Is this an invalid use case or a Hibernate bug?
Thanks,
Gail
[1] https://github.com/hibernate/hibernate-orm/pull/1265
7 years, 3 months
IntelliJ 16 and Java 8 for tests
by Steve Ebersole
We have been having an ongoing discussion about using Java 8 features in
tests. My only argument against that was the fact that doing so makes it
impossible to run tests in IDE (IntelliJ at least) unless I set the
"language level" for the whole module to Java 8 which means I possibly miss
using Java 8 calls in src/main.
Well IntelliJ 16 is in EAP and I have been using it for almost a week now.
One of its major changes is a move to a more Gradle-like view of a module
on importing a Gradle project. So when I import ORM, hibernate-core e.g.
is split up into 2 IntelliJ modules... or more correctly one per
SourceSet. Now I can set the "language level" independently of main versus
test.
So once IntelliJ 16 becomes more stable, I think we can consider allowing
Java 8 features in tests if anyone still wants to.
7 years, 3 months
Stored procedure improvement
by Vlad Mihalcea
Hi,
While writing the stored procedure section, I found a way to improve the
current implementation to FUNCTIONS as well.
Considering the following function:
CREATE FUNCTION fn_post_comments(postId integer)
RETURNS integer
DETERMINISTIC
READS SQL DATA
BEGIN
DECLARE commentCount integer;
SELECT COUNT(*) INTO commentCount
FROM post_comment
WHERE post_comment.post_id = postId;
RETURN commentCount;
END
We could call this function and fetch the result ith plain-old JDBC:
session.doWork(connection -> {
try (CallableStatement function = connection.prepareCall("{ ? =
call fn_count_comments(?) }")) {
function.registerOutParameter(1, Types.INTEGER);
function.setInt(2, 1);
function.execute();
int commentCount = function.getInt(1);
assertEquals(2, commentCount);
}
});
When using the JPA 2.1 API:
StoredProcedureQuery query =
entityManager.createStoredProcedureQuery("fn_count_comments");
query.registerStoredProcedureParameter("postId", Long.class, ParameterMode.IN);
query.setParameter("postId", 1L);
Long commentCount = (Long) query.getSingleResult();
We get a "PROCEDURE fn_count_comments does not exist" exception because the
SQL statement is built as "{call fn_count_comments(?)}" instead of "{ ? =
call fn_count_comments(?) }".
I think we could define a hint like this:
query.setHint(QueryHints.HINT_CALL_FUNCTION, true);
So we could adjust the callable statement to work like a function.
What do you think of this?
Vlad
7 years, 3 months