I know there are loads of entries about this topic. I have already read all of them searching for the problem I am facing.
I have a class/table with a self-reference. This is the Class
public class Comment {
private Integer id;
private Comment parent;
private Issue issue;
private User author;
private String body;
private Date created;
private Date updated;
private Set<Comment> childs;
// All setters and getters
}
And here you can see the hbm.xml file:
<hibernate-mapping>
<class name="Comment" table="COMMENTS">
<id name="id" type="java.lang.Integer">
<column name="ID"/>
<generator class="native"/>
</id>
<many-to-one cascade="all"
class="Comment" fetch="join" name="parent">
<column name="PARENT" not-null="false"/>
</many-to-one>
<many-to-one class="Issue"
fetch="join" name="issue">
<column name="ISSUE" not-null="true"/>
</many-to-one>
<many-to-one class="User"
fetch="join" name="author">
<column name="AUTHOR" not-null="true"/>
</many-to-one>
<property generated="never" lazy="false" name="body" type="java.lang.String">
<column name="BODY" not-null="true"/>
</property>
<property generated="never" lazy="false" name="created" type="java.util.Date">
<column name="CREATED"/>
</property>
<property generated="never" lazy="false" name="updated" type="java.util.Date">
<column name="UPDATED"/>
</property>
<set cascade="delete" fetch="select" inverse="true" lazy="true"
name="childs" sort="unsorted" table="COMMENTS">
<key>
<column name="ID" not-null="true"/>
</key>
<one-to-many class="Comment"/>
</set>
</class>
</hibernate-mapping>
So far everything is fine. But I must have an error somewhere because, when I am running this unit test
Session session = sessionFactory.getCurrentSession();
User user = new User("loginName", "password", "firstName", "lastName", "eMail");
session.save(user);
session.flush();
session.clear();
Issue issue = new Issue();
session.save(issue);
session.flush();
session.clear();
Comment parent = new Comment(issue, user, "body_parent");
session.save(parent);
Comment child = new Comment(issue, user, "body_child_1");
child.setParent(parent);
parent.getChilds().add(child);
session.save(child);
session.flush();
session.clear();
parent = (Comment) session.createQuery("from Comment comment where comment.body='body_parent'").uniqueResult();
System.out.println(parent);
System.out.println(parent.getChilds().iterator().next());
I added the last two lines in order to show you the problem I am facing right now:
COMMENT = [id=1, parentId=<root>, issueId=1, authorId=1, body=body_parent, created=2014-03-08 19:28:54.832, updated=2014-03-08 19:28:54.832, numChilds=1]
COMMENT = [id=1, parentId=<root>, issueId=1, authorId=1, body=body_parent, created=2014-03-08 19:28:54.832, updated=2014-03-08 19:28:54.832, numChilds=1]
Both parent and child are the same! I don't really understand the problem here. When I retrieve the child through a query the result is correct but when I get the child through getChild() there's not query to retrieve the its childs.
Have you any idea? Any clue? I do not see the light at the end of the tunnel here :-/
Thanks a lot in advance!
I finally have realized what the problem was! Well, there was couple of problems.
First, there was no parent_id field in neither the DB nor the class.
Second, there was no exception because I activated inverse property to the set.
The combination of both issues was the problem.
Below, I post the working solution.
Comment.java
public class Comment {
private Integer id;
private Integer parentId; // Parent ID was missing
private Issue issue;
private User author;
private String body;
private Date created;
private Date updated;
private Comment parent; // Reference to parent though parentId
private Set<Comment> childs = new HashSet<Comment>(0);
protected Comment () {
}
// All setters and getters
}
Comment.hbm.xml
<hibernate-mapping>
<class name="es.kazbeel.geckobugtracker.model.Comment" table="COMMENTS">
<id name="id" type="java.lang.Integer">
<column name="ID"/>
<generator class="native"/>
</id>
<property name="parentId" type="java.lang.Integer" update="false" insert="false" column="PARENT_ID" />
<many-to-one class="es.kazbeel.geckobugtracker.model.Issue"
fetch="join" name="issue">
<column name="ISSUE"/>
</many-to-one>
<many-to-one class="es.kazbeel.geckobugtracker.model.User"
fetch="join" name="author">
<column name="AUTHOR"/>
</many-to-one>
<property generated="never" lazy="false" name="body" type="java.lang.String">
<column name="BODY"/>
</property>
<property generated="never" lazy="false" name="created" type="java.util.Date">
<column name="CREATED"/>
</property>
<property generated="never" lazy="false" name="updated" type="java.util.Date">
<column name="UPDATED"/>
</property>
<many-to-one name="parent" class="es.kazbeel.geckobugtracker.model.Comment" column="PARENT_ID" not-null="false" />
<set name="childs" table="COMMENTS" lazy="false" cascade="all-delete-orphan" inverse="false">
<key column="PARENT_ID" />
<one-to-many class="es.kazbeel.geckobugtracker.model.Comment"/>
</set>
</class>
</hibernate-mapping>
I hope this is helpful for someone in the future. This is the first time I post a self-solution :)
Take a shot using the code below:
Comment parent = new Comment(issue, user, "body_parent");
Comment child = new Comment(issue, user, "body_child_1");
child.setParent(parent);
parent.getChilds().add(child);
session.save(parent);
session.flush();
session.clear();
from this
your issue will be resolved by properly defining cascading depedencies
or by saving the referenced entities before saving the entity that
references. Defining cascading is really tricky to get right because
of all the subtle variations in how they are used.
cascade="delete"
check the options all|none|save-update|delete|all-delete-orphan
session.save(child); instead of this try cascade="all" and session.save(parent) so that all child objects will be saved with parent.
Related
I have 2 POJO, Event and OrganizerProfile. Their relationship are many to one.
If I retrieve the Event from database, the OrganizerProfile is showing as empty from the debugger instead of what it should be. Also, I have to leave the hibernate session open to call the event.getOrganizerProfile.
If I get the Event, close the hibernate session, then the OrganizerProfile in the Event cannot be retrieved.
new EventDTO(this.getEvtByDateAddress(_event.getDate(), _event.getAddress(), /*dont close sess*/false));
Can you please explain this?
Thanks
<hibernate-mapping package="com.example.client.serializable">
<class name="Event" table="event">
<id name="oid" type="long" column="oid">
<generator class="increment">
<param name="initial_value">1</param>
</generator>
</id>
<property name="evtName">
<column name="evtName"/>
</property>
<property name="address">
<column name="address"/>
</property>
<property name="date" type="date">
<column name="date"/>
</property>
<many-to-one name="organizerProfile" cascade="all"></many-to-one>
</class>
</hibernate-mapping>
<hibernate-mapping package="com.example.client.serializable">
<class name="OrganizerProfile" table="organizerprofile">
<id column="oid" name="oid" type="long">
<generator class="increment">
<param name="initial_value">1</param>
</generator>
</id>
<property generated="never" lazy="false" name="acctOid">
<column name="acctOid"/>
</property>
<property generated="never" lazy="false" name="email">
<column name="email"/>
</property>
<property generated="never" lazy="false" name="name">
<column name="name"/>
</property>
<property generated="never" lazy="false" name="contact">
<column length="5120" name="contact"/>
</property>
<property name="profilePicName">
<column name="profilePicName"/>
</property>
</class>
</hibernate-mapping>
public Event getEvtByDateAddress(Date _date, String _address, boolean _closeSess)
{
try
{
if(!session.isOpen())
{
session = HibernateUtil.getSessionFactory().openSession();
}
session.beginTransaction();
Criteria criteria = session.createCriteria(Event.class);
criteria.add(Restrictions.eq("date", _date));
criteria.add(Restrictions.eq("address", _address));
Event evt = (Event)criteria.uniqueResult();
if(_closeSess)
{
session.close();
}
if (evt==null)
{
LogUtils.logInfo("The event does not exist: " + _date + " " + _address);
return null;
}
else
{
return evt;
}
}
catch(Exception e)
{
LogUtils.logInfo(e.toString());
if(_closeSess)
{
session.close();
}
return null;
}
}
public EventDTO(Event _event)
{
this.oid=_event.getOid();
this.evtName=_event.getEvtName();
this.address=_event.getAddress();
this.date=_event.getDate();
this.evtPicName=_event.getEvtPicName();
this.organizerProfile=new OrganizerProfileDTO(_event.getOrganizerProfile());
}
<many-to-one name="organizerProfile" cascade="all"></many-to-one>
Since you did not specify the property lazy in your many-to-one mapping, the associated entities will be proxied (see hibernate mapping documentation point 12) thus your related entity is not fetched and cannot be accessed outside of the session, inside of the session you can access it, because hibernate will automatically fetch it when you try to access it.
If you want to access the related entity outside of the session you have to fetch it manually, let hibernate initialize it - both within the session - or you can set your fetch type to eager ( <many-to-one name="organizerProfile" cascade="all" lazy="false"></many-to-one>) which I would NOT recommend (N+1 selects Problem).
Example of manual fetching with your code:
Criteria criteria = session.createCriteria(Event.class);
criteria.setFetchMode("organizerProfile", FetchMode.JOIN);
criteria.add(Restrictions.eq("date", _date));
criteria.add(Restrictions.eq("address", _address));
Also possibly helpful to read: Hibernate 4.3 docs #20: Performance fetching
I am trying to insert data to the DB using hibernate . Here is how I going perform that action
session.beginTransaction();
pojo.StuDetails stu = new StuDetails();
stu.setFName(f_name);
stu.setLName(l_name);
stu.setSex(sex);
stu.setDob(dob);
pojo.Subject sub = new Subject(subject, day, time);
pojo.SubjectHasStuDetails shs = new SubjectHasStuDetails(stu, sub);
session.save(shs);
session.getTransaction().commit();
But It gives me an error saying
Exception in thread "main"
org.hibernate.TransientPropertyValueException: Not-null property
references a transient value - transient instance must be saved before
current operation
Here is my student details entity
public class StuDetails implements java.io.Serializable {
private Integer id;
private String FName;
private String LName;
private String sex;
private String dob;
private Set subjectHasStuDetailses = new HashSet();
...
//constructors and getters, setters
My StudentDetails hbm.xml
<hibernate-mapping>
<class name="pojo.StuDetails" table="stu_details" catalog="laravel_test" optimistic-lock="version">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="identity" />
</id>
<property name="FName" type="string">
<column name="f_name" length="45" not-null="true" />
</property>
<property name="LName" type="string">
<column name="l_name" length="45" not-null="true" />
</property>
<property name="sex" type="string">
<column name="sex" length="45" not-null="true" />
</property>
<property name="dob" type="string">
<column name="dob" length="45" not-null="true" />
</property>
<set name="subjectHasStuDetailses" table="subject_has_stu_details" inverse="true" lazy="true" fetch="select">
<key>
<column name="stu_details_id" not-null="true" />
</key>
<one-to-many class="pojo.SubjectHasStuDetails" />
</set>
</class>
</hibernate-mapping>
My Subject Entity looks like
public class Subject implements java.io.Serializable {
private Integer id;
private String subName;
private String day;
private String time;
private Set subjectHasStuDetailses = new HashSet();
...
//constructors and getters, setters
Subject.hbm.xml
<hibernate-mapping>
<class name="pojo.Subject" table="subject" catalog="laravel_test" optimistic-lock="version">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="identity" />
</id>
<property name="subName" type="string">
<column name="sub_name" length="45" not-null="true" />
</property>
<property name="day" type="string">
<column name="day" length="45" not-null="true" />
</property>
<property name="time" type="string">
<column name="time" length="45" not-null="true" />
</property>
<set name="subjectHasStuDetailses" table="subject_has_stu_details" inverse="true" lazy="true" fetch="select">
<key>
<column name="subject_id" not-null="true" />
</key>
<one-to-many class="pojo.SubjectHasStuDetails" />
</set>
</class>
</hibernate-mapping>
Here is the SubjetcHasStuDetails Entity
public class SubjectHasStuDetails implements java.io.Serializable {
private Integer id;
private StuDetails stuDetails;
private Subject subject;
...
//constructors and getters, setters
SubjectHasStuDetials.hbm.xml
<hibernate-mapping>
<class name="pojo.SubjectHasStuDetails" table="subject_has_stu_details"
catalog="laravel_test" optimistic-lock="version">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="identity" />
</id>
<many-to-one name="stuDetails" class="pojo.StuDetails" fetch="select">
<column name="stu_details_id" not-null="true" />
</many-to-one>
<many-to-one name="subject" class="pojo.Subject" fetch="select" >
<column name="subject_id" not-null="true" />
</many-to-one>
</class>
</hibernate-mapping>
Can someone help me on this error please ... Thanks..
In your SubjectHasStuDetials.hbm.xml make these changes :
<many-to-one name="stuDetails" class="pojo.StuDetails" fetch="select" cascade="all">
<column name="stu_details_id" not-null="true" />
</many-to-one>
<many-to-one name="subject" class="pojo.Subject" fetch="select" cascade="all" >
<column name="subject_id" not-null="true" />
</many-to-one>
Add cascade="all" attribute to both stuDetails and subject many-to-one tags.
Cascade attribute is mandatory, when ever we apply relationship
between objects, cascade attribute transfers operations done on one
object onto its related child objects
If we write cascade = “all” then changes at parent class object will
be effected to child class object too, if we write cascade = “all”
then all operations like insert, delete, update at parent object will
be effected to child object also.
Example: if we apply insert(or update or delete) operation on parent
class object, then child class objects will also be stored into the
database.
I'm trying to achieve lazy load on the following.
User.java
public class User {
private int id;
private String userName;
private String password;
private Employee employee;
//getter and setters
}
User.hbm.xml
<hibernate-mapping>
<class name="com.site.dto.User" table="user">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="identity" />
</id>
<property name="userName" type="string" update="false">
<column name="user_name" length="50" not-null="true" unique="true" />
</property>
<property name="password" type="string">
<column name="password" length="50" not-null="true" unique="true" />
</property>
<one-to-one name="employee" class="com.site.dto.Employee" fetch="select" cascade="save-update" />
</class>
</hibernate-mapping>
Employee.java
public class Employee implements Serializable{
private int id;
private String name;
private String email;
private User user;
// getter and setters
}
Employee.hbm.xml
<hibernate-mapping>
<class name="com.site.dto.Employee" table="employee">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="identity" />
</id>
<property name="name" type="string">
<column name="name" length="50" not-null="true" unique="true" />
</property>
<property name="email" type="string" update="false">
<column name="email" length="50" not-null="true" unique="true" />
</property>
// enforcing many-to-one to one-to-one by putting unique="true"
<many-to-one name="user" column="user_id" class="com.site.dto.User" unique="true" not-null="true" fetch="select" cascade="save-update" />
</class>
</hibernate-mapping>
First I'm getting the User Object based on username. Now I'm trying to load the employee object which gives me null pointer exception. So after digging on some debug, it seems to be using a select statement with wrong where clause. Here is the hibernate debug
select employee0_.id as id1_1_0_, employee0_.name as name2_1_0_, employee0_.email as email3_1_0_,employee0_.user_id as user_id25_1_0_, from employee employee0_ where employee0_.id=?
Why is the where clause is based on employee.id and not employee.user.id ? I think this is due to the reason on how one-to-one mapping works in hbm.xml configuration where one-to-one will be linked to child table's primary key id but not user_id. I'm forcing the many-to-one to one-to-one in employee by using unique="true". I can fetch the employee in Hibernate annotation's one-to-one by defining #Join-column but I can't figure out how to map the one-to-one in hbm.xml which should refer the child's user_id.
Figured out the solution a while back, but forget to post it.
The above problem is coz, by default one-to-one mapping will be implemented for a child table which have the parent's primary key as the Child's primary key. So if we're going to eliminate that default property and use one-to-one with many-to-one (unique=true), we should define property-ref
I've added property-ref in one-to-one mapping in User.hbm.xml and now it works fine.
<one-to-one name="employee" property-ref="user" class="com.site.dto.Employee" fetch="select" cascade="save-update" />
I am following Hibernate Documentation and trying to implement the example given for section 9.4. Components as composite identifiers but facing issues on how to implement it.
Here is what I have done:
My entity classes:
Order.java
public class Order {
private int id;
private Set<OrderLine> lines = new HashSet<OrderLine>();
// Setters & Getters
}
OrderLine.java
public class OrderLine {
private OrderLineId id;
private String name;
private Order order;
// Setters & Getters
}
OrderLineId.java
public class OrderLineId implements Serializable{
private int lineId;
private int orderId;
private int customerId;
// Setters & Getters
}
My mapping file which is having issues:
<hibernate-mapping>
<class name="Order" table="TEST_Order">
<id name="id" type="int" column="id">
<generator class="native"/>
</id>
<set name="lines" cascade="all">
<key column="orderId"/>
<one-to-many class="OrderLine"/>
</set>
</class>
<class name="OrderLine" table="TEST_OrderLine">
<composite-id name="id" class="OrderLineId">
<key-property name="lineId"/>
<key-property name="orderId"/>
<key-property name="customerId"/>
</composite-id>
<property name="name"/>
<many-to-one name="order" class="Order"
insert="false" update="false">
<column name="orderId"/>
<column name="customerId"/>
</many-to-one>
</class>
</hibernate-mapping>
When I am trying to create a session factory which parses this mapping file, I am getting an exception saying:
Caused by: org.hibernate.MappingException: Foreign key (FK_89b4nqt5l2n6tfd1d5tq0ill0:TEST_OrderLine [orderId,customerId])) must have same number of columns as the referenced primary key (TEST_Order [id])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:110)
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:93)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1816)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1739)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1424)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
Can someone please help me how to implement the example given in the documentation.
The OrderLine needs to reference the Order PK, which is not a composite key.
It means the many-to-one must be:
<many-to-one name="order" class="Order"
insert="false" update="false">
<column name="orderId"/>
</many-to-one>
The orderId is the FK to Order.id.
Then the one-to-many side will become:
<set name="lines" cascade="all">
<key>
<column name="orderId"/>
</key>
<one-to-many class="OrderLine"/>
</set>
So even if the OrderLine has a composite-key, the reference is made after Order.id, which is a simple key.
If you want to map other association to OrderLine, like OrderLineProduct then you'll need to use the composite-key to map the association between the parent (OrderLine) and the child (OrderLineProduct), so that OrderLineProduct has a composite-foreign-key back to OrderLine.
In both the table hbm mapping you should have same no. of column ,what you are using to make composite.You need to add these 3 column in TEST_Oder.
Example to follow :
<many-to-one name="orderLine" class="OrderLine">
<column name="lineId"/>
<column name="orderId"/>
<column name="customerId"/>
</many-to-one>
Refer same URL
I'm having this error at Netbeans in my Java code:
org.hibernate.MappingException: Foreign key (FK12A711396456CA10:devolucion_master [devolucion_consecutivo])) must have same number of columns as the referenced primary key (devolucion [detalle_ticket_id,detalle_ticket_ticket_id,detalle_ticket_fondo_fijo_id,detalle_ticket_caja_id,consecutivo]
I made a foreign key from DevolucionMaster to Devolucion, using "consecutivo" from Devolucion to my variable "consecutivo" for DevolucionMaster, the problem is that for Devolucion the "key" is composite key, and I only use for the foreign key one element of the key, maybe that's why (that it needs to be used the 5 that makes the primary key).
Here's the DevolucionMaster.hbm.mxl:
<hibernate-mapping>
<class catalog="pos" name="dunosusa.pos.model.DevolucionMaster" table="devolucion_master">
<composite-id class="dunosusa.pos.model.DevolucionMasterId" name="id">
<key-property name="id" type="int">
<column name="id"/>
</key-property>
<key-property name="detalleTicketTicketId" type="int">
<column name="detalle_ticket_ticket_id"/>
</key-property>
<key-property name="detalleTicketFondoFijoId" type="int">
<column name="detalle_ticket_fondo_fijo_id"/>
</key-property>
<key-property name="detalleTicketCajaId" type="int">
<column name="detalle_ticket_caja_id"/>
</key-property>
</composite-id>
<many-to-one class="dunosusa.pos.model.Devolucion" fetch="select" name ="devolucion">
<column name="devolucion_consecutivo" not-null="true"/>
</many-to-one>
<many-to-one class="dunosusa.pos.model.Usuario" fetch="select" name="usuario">
<column length="6" name="usuario_clave_autorizo"/>
</many-to-one>
<many-to-one class="dunosusa.pos.model.Ticket" fetch="select" insert="false" name="ticket" update="false">
<column name="detalle_ticket_ticket_id" not-null="true"/>
<column name="detalle_ticket_fondo_fijo_id" not-null="true"/>
<column name="detalle_ticket_caja_id" not-null="true"/>
</many-to-one>
<property name="total" type="big_decimal">
<column name="total" not-null="true" precision="10"/>
</property>
<property name="fecha" type="timestamp">
<column length="19" name="fecha"/>
</property>
</class>
</hibernate-mapping>
here the Devolucion.hbm.xml:
<hibernate-mapping>
<class catalog="pos" name="dunosusa.pos.model.Devolucion" table="devolucion">
<composite-id class="dunosusa.pos.model.DevolucionId" name="id">
<key-property name="detalleTicketId" type="int">
<column name="detalle_ticket_id"/>
</key-property>
<key-property name="detalleTicketTicketId" type="int">
<column name="detalle_ticket_ticket_id"/>
</key-property>
<key-property name="detalleTicketFondoFijoId" type="int">
<column name="detalle_ticket_fondo_fijo_id"/>
</key-property>
<key-property name="detalleTicketCajaId" type="int">
<column name="detalle_ticket_caja_id"/>
</key-property>
<key-property name="consecutivo" type="int">
<column name="consecutivo"/>
</key-property>
</composite-id>
<many-to-one class="dunosusa.pos.model.MotivoDevolucion" fetch="select" name="motivoDevolucion">
<column name="motivo_devolucion_id" not-null="true"/>
</many-to-one>
<many-to-one class="dunosusa.pos.model.DetalleTicket" fetch="select" insert="false" name="detalleTicket" update="false">
<column name="detalle_ticket_id" not-null="true"/>
<column name="detalle_ticket_ticket_id" not-null="true"/>
<column name="detalle_ticket_fondo_fijo_id" not-null="true"/>
<column name="detalle_ticket_caja_id" not-null="true"/>
</many-to-one>
<many-to-one class="dunosusa.pos.model.ControlCorte" fetch="select" name="controlCorte">
<column name="control_corte_fondo_fijo_id" not-null="true"/>
<column name="control_corte_caja_id" not-null="true"/>
</many-to-one>
<property name="cantidad" type="big_decimal">
<column name="cantidad" precision="8"/>
</property>
<property name="fecha" type="timestamp">
<column length="19" name="fecha"/>
</property>
<property name="comentario" type="string">
<column length="150" name="comentario"/>
</property>
<property name="controlDevolucion" type="boolean">
<column name="control_devolucion" not-null="true"/>
</property>
<set name="devolucionMasters" inverse="true">
<key>
<column name="devolucion_consecutivo" not-null="true" />
</key>
<one-to-many class="dunosusa.pos.model.DevolucionMaster" />
</set>
</class>
</hibernate-mapping>
DevolucionMaster.java: (only the variables, not the set and get)
public class DevolucionMaster implements java.io.Serializable {
private DevolucionMasterId id;
private Devolucion devolucion;
private Usuario usuario;
private Ticket ticket;
private BigDecimal total;
private Date fecha;
}
Devolucion.java: (same as for DevolucionMaster)
public class Devolucion implements java.io.Serializable {
private DevolucionId id;
private MotivoDevolucion motivoDevolucion;
private DetalleTicket detalleTicket;
private ControlCorte controlCorte;
private BigDecimal cantidad;
private Date fecha;
private String comentario;
private boolean controlDevolucion;
private Set devolucionMasters = new HashSet(0);
}
I don't know what's my error, I've searched over internet about similar errors but no one solution I've read has worked (forgive my bad english).
Thanks a lot!
Yes, you have a composite primary key for the Devolucion class, and you are trying to refer to it by just one simple column/field devolucion_master.devolucion_consecutivo.
I don't know of a way to easily tell Hibernate that devolucion_consecutivo column is actually of type dunosusa.pos.model.DevolucionId.
That's why I have never used composite primary keys. I always have one primary key of type Long (bigint) and enforce uniqueness for a composition of foreign keys where it's needed. It's easier to work with, no issues like the one you're having.
APPENDIX:
I just did some digging and, actually, there is a way to do it :-)
But as I said it's not as easy as using single column PK/FK keys.
Instead of this:
<hibernate-mapping>
<class catalog="pos" name="dunosusa.pos.model.DevolucionMaster" table="devolucion_master">
...
<many-to-one class="dunosusa.pos.model.Devolucion" fetch="select" name="devolucion">
<column name="devolucion_consecutivo" not-null="true"/>
</many-to-one>
...
You should list all PK columns in the FK like this:
<hibernate-mapping package="dunosusa.pos.model">
<class catalog="pos" name="DevolucionMaster" table="devolucion_master">
...
<many-to-one class="Devolucion" fetch="select" name="devolucion">
<column name="devolucion_detalle_ticket_id" not-null="true"/>
<column name="devolucion_detalle_ticket_ticket_id" not-null="true"/>
<column name="devolucion_detalle_ticket_fondo_fijo_id" not-null="true"/>
<column name="devolucion_detalle_ticket_caja_id" not-null="true"/>
<column name="devolucion_consecutivo" not-null="true"/>
</many-to-one>
...
A little advice - use the package attribute of the hibernate-mapping element so you don't have to type it in everywhere - it makes it more readable.
Good luck.