field « Field « JPA Q&A

1. Is it necessary to check all the field in equals method of model class as i am using JPA?

Is it necessary to check all the field in equals method of model class as i am using JPA ? please reply.... can i use only id...?

2. How to handle choice field with JPA 2, Hibernate 3.5

I have an entity with Integer attributes that looks like this in proto code:

class MyEntity:
    String name

    @Choices({1, "BSD", 2, "Apache", 3, "GPL"}

3. LazyInitializationException when field is eager

I have class OmQcActivity like this:

@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class OmQcActivity{
   @ManyToOne(fetch = FetchType.EAGER)
   private Codesc status;
codesc is another entity. In my code I wrote:
OmQcActivity  ...

4. NoSuchFieldError but the field is there

I just upgraded a library, and another one started throwing NoSuchFieldError. It would be fine, if the field was removed. But it stays. It's just deprecated.

Hibernate.TIMESTAMP.nullSafeGet(null, null); // << works

new PersistentDateTime().nullSafeGet(null, ...

5. computed field and Hibernate

Remind me: how do I map a Java class with a computed field that should be persisted? I.e.:

public class PolicyHolder {
    private int height;
    private ...

6. Retrieving values of a specific field in Hibernate

Consider a class:

class Employee{
 Integer empId,
  //many other fields
I need a DAO method as shown below
 List<Integer> getAllEmployeeIds(){
I dont want List<Employee> and  (NEW EDIT) Set<Intger>
How can i ...

7. where on any field in hibernate

I have the following object:


I would like to return hibernate object if the text "big" appers in any of the fields. Is there a better way than SQL query: select distinct id ...

8. Is it possible to have immutable fields in Hibernate/JPA?

In our application, we need to have fields that are assignable only once. At first we thought of encapsulating the fields and making the setters private. However, some questions arouse:

  • Without a public ...

9. Hibernate AutoGenerated Field not working with RCP

Hi, I have an RCP application that uses hibernate for JPA. I have it working for read/update but the create does not work. My entity beans work find outside of the ...

10. problem with JPA and autoincrement fields

Hi, I created a database in postgres 8.3 with a PK defined by a SERIAL value (see SQL code below). Then in Netbeans 6.1 (Toplink) I created the related entity (see code below). The problem is that "@GeneratedValue" annotation wasn't created and I had to add it manually. Is it a netbeans bug or I mistook something? ------------------------------------------ CREATE TABLE "public"."xmppservice" ...

11. Hibernate: Accessors vs. Direct Field Access

I've recently begun a project to convert an EJB application (session and entity) to Hibernate and have an architecture question for those that have blazed ahead. I've read in a few places now that using accessor methods is recommended over direct field access for the mappings. However, this makes my public accessors less elegant than I had hoped. When a client ...

12. JPA optional field

I use JPA (Toplink) and was wondering if there is such thing as optional field. Let me explain what I mean: I'm writing application that can connect to different databases. For example let's say that in all databases there is table "products", but some have field "quantity", and some not. So I was wondering if I can have one entity class ...

13. Hibernate CompositeUserType with repeated field

I am attempting to create a mapping within Hibernate which requires a CompositeUserType. The user type consists of 2 fields one of the columns is used within a separate composite type. The problem is that I get an error message stating that the repeating column must be set to insert/update to false, unfortunately I am not able to set the individual ...

14. org.springframework.orm.hibernate3.HibernateSystemException: could not set a field value by reflecti

Hi I am new to hibernate. I am getting this exception on running my main class /** * Campaign priority */ private int priority = 0; /** * @return the priority */ public int getPriority() { return priority; } /** * @param priority the priority to set */ public void setPriority(int priority) { this.priority = priority; } the priority field create ...

16. Filter for calculated fields

17. Hibernate overwriting field value during flush() ?

Newbie Joined: Thu Feb 18, 2010 12:49 pm Posts: 1 Hi I have a strange problem where hibernate seems to be overwriting a field in a DTO object during the session.flush() I am using hibernate 3.2.7 and Oracle JDBC driver When I call session.flush() to write data to the database, I get an exception, with this as the root cause: ...

18. changes to the fields are not detected

EntityManager em = getEM(); User uu = new User(); em.persist(uu); uu.setLogin("qqq"); em.getTransaction().begin(); em.getTransaction().commit(); // Exception: login is null

20. Many-To-Many with additional fields

Newbie Joined: Sat Jun 04, 2011 8:08 am Posts: 2 Please help, I'm stuck for several days. Read lots of tutorials, forums, and no working answer found. The problem is a simple situation: many-to-many with jointable and additional fields in the jointable. HibernateTools generate code for me like below. THE PROBLEM IS: I cannot add anything to the jointable I have ...

21. Field Transformation Needed

Hi, I have a Currency table, which stores comma separated ascii codes for the currency label (For example for dollar, 36 is stored which represents $). Since we don't manage the table the data in it can't be changed. For our purposes, we want to transform the ascii code to the proper representation while loading data from database. Does hibernate provide ...

22. mappedBy references wrong field after obfuscation

Hi! We use a bidirectional ManyToMany connection with a Jointable like this: Code: @Entity(name="group") public class Group { ... @ManyToMany(targetEntity = User.class) @JoinTable(joinColumns = @JoinColumn(name = "group_id"), inverseJoinColumns = @JoinColumn(name = "user_id")) private Set users = new HashSet(); } @Entity public class User { ...

23. Hibernate Question - Base fields

I Have public class BaseDTO { private static final long serialVersionUID = 1L; private Timestamp inserDate; private Timestamp updateDate; public Timestamp getInserDate() { return inserDate; } public void setInserDate(Timestamp inserDate) { this.inserDate = inserDate; } public Timestamp getUpdateDate() { return updateDate; } public void setUpdateDate(Timestamp updateDate) { this.updateDate = updateDate; } } public class DetailDTO extends BaseDTO { private String id; ...

24. Problems with Clob field

Hi, I am trting to read a clob field from the oracle table and I am getting the following exception. I am using Oracle 9i Database Server. java.lang.AbstractMethodError: oracle.jdbc.driver.OracleResultSetImpl.getClob(Ljava/lang/String;)Ljava/sql/Clob; at com.imi.poc.entity.StringClobType.nullSafeGet( at net.sf.hibernate.type.CustomType.nullSafeGet( at net.sf.hibernate.type.AbstractType.hydrate( at net.sf.hibernate.loader.Loader.hydrate( at net.sf.hibernate.loader.Loader.loadFromResultSet( at net.sf.hibernate.loader.Loader.instanceNotYetLoaded( at net.sf.hibernate.loader.Loader.getRow( I am using the follwing code and mapping file for loading the Object from the DB. Java Code ...

25. Generating calculated fields

Hi, I am using middlegen to get the hbm.xml files from my database. I want to manipulate some redundant information in the way that I am going to explain. For example I have a user table with: firstname, lastname, sex, age. I can say that name = lastname, firstname. can I specify to middlegen to generate a get method with that ...

27. Thread Local Session pattern and static fields

gavin wrote: eh? I'm trying to think what you might mean by this .... how would clustering affect anything? A single JVM ensures that a static field is only loaded once by the classloader. This is differnt in a J2EE Container. First of all you have different class loaders per JVM. But this is okay as each classloader is responsible for ...

28. help for derived field

I would like to know if we can map into parts of a field (using Hibernate 2.0). For example, field "RESC" is composed of "TYPE"+"LEVEL"+"MODE". like this, "HTL34GLOBAL" is "HTL" + "34" + "GLOBAL". I want to be able to get to the "TYPE", "LEVE:, "MODE" subfields. Hibernate 2.0 does not support this. In Hibernate 2.1, we can use the "formula" ...

29. '' Field Value problem

I have some FK'd declared on the database level. I didn't tell Hibernate about them because I felt it would be cumbersome to make an object out of a table with a single string field. I just wanted referential integrity enforced by something and it seemed easiest to do it that way. Problem is now that when I insert a (mostly ...

30. Direct field access

31. access=field support in xdoclet

Is there anyway to use xdoclet tags to set the access method for a property? I can't find anything in the docs. If not any recommended work arounds? Like a way to set the default method to access=field. If not then I will post process the hbm.xml files with some xml processor to add them. I have a legacy app that ...

32. Checking isDirty on fields

33. memory question about the 'executions' field in SessionImpl

Hi, During a very long transaction (a massive data update on about 100 000 different objects), even with session.clear(), I noticed that the session was consuming more and more memory. After investigations, it seems that the problem was coming from the SessionImpl.executeAll() method which adds to the 'executions' field an Executable object. The 'executions' field is cleared only at the end ...

34. why access="field" can not work?

In class A .. private String pPackageId; public void setPPackageId(String ppkgId) { this.pPackageId = ppkgId; } public String getPPackageId() { return pPackageId; } ... in the hbm.xml file : but I caught the following exception: PropertyNotFoundException: Could not find a getter for pActivityId in class why?

35. Function generated field

Hi folks, I have a function within SQL Server that is executed by a trigger on an insert and sets a field with a calculated value. This field is not a PK nor FK. When Hibernate is done saving my POJO, the field is not returned with the calculated value. I was wondering why that is? If I do session.refresh(pojo) then, ...

36. Direct Field Access vs. Accessors

I've recently begun a project to convert an EJB application (session and entity beans) to Spring/Hibernate and have an architectural question for those that have blazed ahead. I've read in a few places that using accessor methods is recommended over direct field access for the mappings. However, this makes my public accessors less elegant than I had hoped. When a client ...

37. What is the tradeoff when access="field"?

Is there any reason why this option is not the default? I find that the more I want to make my domain objects responsible for business rules and validation, the more I turn this option on to make sure this code does not get executed when hibernates needs to get and set values. What is the trade off for setting this ...

38. Custom Fields

39. how to derefrence a field

40. Problem adding a field

I get the following error in the stacktrace: [hibernatetool] 23:56:25,806 ERROR Configuration:365 - Could not compile the mapping document [hibernatetool] org.hibernate.PropertyNotFoundException: field not found: mandant I know that there is no field mandant yet - i want hibernatetool to generate the java source with these field. Has anyone an idea, why the code is not generated? thanks in advance ! Hibernate ...

41. Problem getting at uninitialzed fields

Hey all, I'm having an issue implementing a generic sorter for my Hibernate objects. I have three classes: Product Type is many-to-one to Product is one-to-many to Manufacturer I have a web app which displays all Product Types in a system, and which allows you to sort from a variety of criteria, including any fields in ProductType or any fields in ...

42. Feature Question: Field Restriction

This is more of a general question that I have not been able to determine by reviewing the documentation. Is it possible to restrict the fields that Hibernate retrieves for a POJO? I've got tables/POJOs that have 60-70 fields each and in some situations I want to retrieve all the fields. However in other situations I only want to retrieve a ...

43. Calculated Fields

Is it possible to reference a calculated field in the calculation of a another calculated field? eg (x multiplyby y) (this.prop1 divideby z) ie prop2 will equate to (x*y)/z OR is the only way to do this, to use the sql used in prop1 and repeat in prop2 to get same value? Thanks

44. calculated field -- obtaining the result.

I'm simply trying to get the calculated distance back out of the hql below. I've been told formulas (which I can't see working because this is parameterized -- I need to specify a second lat/lon for the distance) and filters. The filter seems like a better way to do the query but it still doesn't help me get the distance back ...

45. float fields difference from linux and windows ?

Hi, I have some probelm with float filed with mysql. I developed an application with Hibernate 3.1.2, Windows 2000, Mysql 5.0.18, jdk 1.5_06, mysql Connector 3.1.12 and all works. When I deploy application on LInux (Debian 3.1, Mysql 5.0.20, jdk 1.5_06, mysql Connector 3.1.12 , Hibernate 3.1.12) I found a problem on all float field update. I have a table like ...

46. one-to-one & mandatory fields

47. Does Comparable#compareTo() have to use accessors vs fields?

I've just been reading "Hibernate in Action"; it's an excellent book and has helped me a lot. It's definitely an essential complement to the reference docs. Anyway, it says on p. 125 that equals() and hashCode() methods should use accessors (getters) instead of reading the "other" object's fields directly. This is all well and good (although I'm a little mystified about ...

48. Newbie question referencing the same class from two fields

I'm strageling with this for some time now, so please forgive me if its a stupid question. I have two classes, User with ID and name And Message with text ,fromUser and toUser. I write HBM files and run hbm2java and hbm2ddl to create .java and .sql files. My question is: how do I define this relationship in the HBM so ...

49. new field in class

Perhaps I'm misunderstanding your question (or else you are very much a newbie). To add a column to an existing table without destroying data is done with a simple SQL statement: ALTER TABLE table_name ADD new_column_name data_type For example, to add a VARCHAR(100) column called DESC to table FOO: ALTER TABLE foo ADD desc varchar(100) Depending on your database you might ...

50. cglib optimizer and direct reflective access of fields

Hibernate uses AOP which is done around your getters and setters, that's where the "magic" happens, if you bypass the magic, "getters and setters" then directly accessing your object with reflection is not gonig to do anything. Why don't you just change your reflection class to call a specific getter or setter instead of accessing the feilds directly?

51. field access behavior question

Beginner Joined: Mon Aug 22, 2005 1:22 am Posts: 36 I have a class (ScoringEvent) that has a property defined by field access. ScoringEvent.hbm.xml Code:

52. How to escape field in the request ?

Hibernate Name and version of the database you are using: mysql Hi, I try to use schema exporter in my test. The export don't work because one field name is a sql keyword and there is no quote in the generated sql : GRAVE: Unsuccessful: create table mytable (id bigint not null, int integer, primary key (id)) 27 mai 2007 ...

53. [Security on a field-level]

Hello guys, I'm trying to implement security on a field-level for my application using Spring/Acegi/Hibernate. I have roles on a database that defines if an user has access to a certain field on my bean. Researching on Hibernate JavaDocs I notice the interface org.hibernate.bytecode.BytecodeProvider It seems to provide field-access instumentation getTransformer(org.hibernate.bytecode.util.ClassFilter, org.hibernate.bytecode.util.FieldFilter) Does anyone know where should I plug this? I ...

54. the mutable field not working !!!

Hi. Following are the tools I am using : 1) MySql server 5.0 2) Hibernate 3.2.5 3) xml version 1.0 Now when I add the 'mutable="false" attribute in the mapping file, I am able to delete the records from the database using the session.delete(obj) command. I am not being able to figure out just why is this happening ..? I might ...

55. Some objects for same field

hi I have a table that have the fields: objectId(integer) and ObjectType(integer). I would like to make a many-to-one relation using the ObjectType. Example: if the ObjectType == 1 then the class of relation will be the com.myapplication.Product; if the ObjectType == 2 then the class of relation will be the com.myapplication.ServiceOrder if the ObjectType == 3 then the class of ...

56. Get username in EventListener to handle signature fields

Hi everybody, I'm working with a database model that has for each row the old style signature fields (insert & update user/date). To handle that transparently I added a Component with the four fields to each entity. The responsability to populate these fields is left to an EventListener (PreInsert & PreUpdate). As the EventListener has to be stateless, the username is ...

57. org.hibernate.PropertyNotFoundException: field not found

JAVA Class private Lookup lookup; // Contains String lookupCode

59. one searchfield, several fields on the model

Hello people, I can't seem to figure this one out; I have one search field; Name. It's supposed to search on -firstName -middleName -surName I'd like to find an entity if the value is in any of these fields. Example; Marylin Monroe is registered as -firstName : Marolyn -middleName : (nothing) -surName : Monro I'd like to find this entity when ...

60. copying fields

61. SYSDATE in Field

62. how to get particular field from databas

How to retrieve particular field in Hibernate? I have ecourtnumber field in database table VWRecords. I want to retrieve this value. In one another class. How to do to that. What query statement i need to write? I only want ecourtnumber not all fields from table Vwrecords. Thanks in advance for any reply Regards Naresh Vatsal

64. Server restart needed after a Custom Field added?

Hi, We are trying to implementing Hibernate Custom Fields with spring + Hibernate With the support of some documents available on custom Fields approach, we are able to create a custom field properly and can able to see added custom field to database but we are not able to add the data to the newly added custom Field. This might be ...

65. Avoid data race on counter field (with cluster)

66. having a field used in two sub-classes of a single hierarchy

Hibernate Core: Hibernate Annotations: 3.3.0.GA Hibernate EntityManager: 3.3.1.GA We have a single class per hierarchy mapping with a super class and more than 10 sub-classes, some of the sub-classes map the same column on database, when executing a select query on the super-class the aliases created for the column is the same, so by applying pagination on oracle "column ambiguously ...

67. How to make a field as an Autogenerated

javax.persistence.GenerationType.Sequence Some database vendors support the use of a database sequence object for maintaining primary keys. To use a sequence, you set the GenerationType strategy to SEQUENCE, specify the name of the generator annotation, and then provide the @SequenceGenerator annotation that has attributes for defining both the name of the sequence annotation, and the name of the actual sequence object in ...