Hi folks,
I have a Date type column in Oracle DB and it contains date and time for sure. But when I'm trying to get data in java application it will return date with bunch of zeros instead of real time.
In code it'll be like:
SQLQuery sqlQuery = session.createSQLQuery("SELECT table.id, table.date FROM table");
List<Object[]> resultArra...
Is it possible to get a StaleObjectStateException with Hibernate when you do the same query twice inside one tx if the result data of that query gets changed by a concurrent update inside a different session between the first and the second query?
I am using optimistic concurrency control on all entities in this scenario.
So it looks l...
I have a Model class. This class should be able to reference itself, i.e. the resulting "output" from the model should be like this.
Some instanceOf Model.class
|-> Some instanceOf Model.class having parent instance referenced as parent_id
|-> Some instanceOf Model.class having ...........
The instances represent geographical enti...
Hello,
I am new to Java world but I am pretty good at using Flex, actionscript 3, Ant and even Maven to some extent. Now I would like to learn some java and use Hibernate and JBoss (webapp).
I already have Maven working and have found the m2eclipse plugin on the web, it seem pretty nice for maven integration.
Now I would like to know ...
I'm using JPA (Hibernate) and jTDS as my jdbc driver. Whenever the datatype of my entity columns are String, the created prepared statement uses varchar(8000) as its parameter. I've already tried to use @Column(length=50) in my mappings for example, but it seems to be ignored.
If I set sendStringParametersAsUnicode in jTDS connection, i...
I have a Person class which has a String collection of aliases representing additional names that person may go by. For example, Clark Kent may have aliases "Superman" and "Man of Steel". Dwight Howard also has an alias of "Superman".
@Entity
class Person {
@CollectionOfElements(fetch=FetchType.EAGER)
Set<String> aliases = new Tr...
Updated: I wound up "solving" the problem by doing the opposite! I now have the entity reference field set as read-only (insertable=false updatable=false), and the foreign key field read-write. This means I need to take special care when saving new entities, but on querying, the entity properties get resolved for me.
I have a bidirect...
If I want to search those students who take class "Math" and "John" is his group:
shoud I use createCriteria or createAlias?
Criteria:
Criteria criteria = session.createCriteria(Student.class);
Criteria subquery1 = criteria.createCriteria("courses", course).add(Restrictions.eq(course.name, "Math"));
Criteria subquery2 = criteria.creat...
I have a few questions related to batch insert in Spring.
When I do something like that:
public void save(Car car) {
String sql1 = "insert into Car values (1, 'toyota')";
String sql2 = "insert into Car values (2, 'chrysler')";
String sql3 = "insert into Car values (3, 'infinity')";
String[] tab = new String[2];
tab[0] = sql1;...
I'm looking for a tutorial explaining how to work with these 3 technologies, found this one, but it's working with HyperSql DB (yeah, I edited hibernate.cfg.xml to connect with MySql... but I just received a bunch of errors).
...
I have a class User with one field called birthDate which is a java.sql.Date.
How do I do a hql query that will retrieve all Users that are between min and max years old?
(My real scenario is slightly more complex than that but that's where I am stuck right now).
UPDATE
It must be an hql expression so I can put the age expression in a...
Hi,
Currently, in order to check if the Hibernate 2nd-level cache was used for a Database query, I check my SQL log (through p6spy or logSql=true in Datasource.groovy) to see if the Grais/Hibernate triggered an SQL query. And I assume that if the query was not logged, it might mean that cache was used.
It is pretty complicated for a ...
I am trying to do spring transactions with @Transactional without any success.
Excerpt from my applicationContext.xml:
<context:annotation-config />
<context:component-scan base-package="hibex" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="org.postgresql.Driver"...
I've learnt recently that it is possible to create new objects in JPQL statements as follows:
select new Family(mother, mate, offspr)
from DomesticCat as mother
join mother.mate as mate
left join mother.kittens as offspr
Is this something to be avoided or rather to embrace? When is usage of this feature justified in the light ...
All, when I first call buildSessionFactory, Hibernate seems to be running a bunch of queries on my DB. They vary from being "selects" to "insert"s. Why is this and how can I stop it?
Edit: After some review, no the queries are not random. They seem to be inserts, selects and deletes into the tables on my DB. It almost looks like Hiberna...
I'm attempting to use hibernate entity manager with mysql and glassfish. I'm getting the following error when attempting to use a JTA datasource:
Caused by: org.hibernate.HibernateException: The chosen transaction strategy requires access to the JTA TransactionManager
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFact...
my entity class is annotated with @Cache, my primary keys are combined of few table fields, primary keys are embedded into this class as embedded class. Do I need to put @Cache for the embedded class as well?
...
I'm new to Grails.
I'm trying to experiement with my grails domains from the shell, and I can't get it to work. These domains work fine from the scaffold code when I run the app.
Given this domain class
class IncomingCall {
String caller_id
Date call_time
int call_length
static constraints = {
}
}
I try to cre...
Hi!
I have a strange Hibernate behaviour in my program.
I have two classes with onetomany relation: good and price:
@Entity
@Table(name="GOODS")
public class Good {
....
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
@JoinColumn(name="GOOD_ID")
private Set<Price> prices = new HashSet<Price>();
...
Hy guys,
I am working on a project developed in JEE 5 environment. I want to know how I can declare a Hibernate event listener so that I can be informed when CRUD operation are performed.
I've read that I must declare in the Hibernate configuration file *cfg.xml something like this:
<hibernate-configuration>
<session-factory>
...