facebook

Hibernate insert problem in field number

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #229539 Reply

    rbandeira
    Member

    Hi to all,

    I have a problem when i save an object. The type of the field is number(10) in oracle database and i send the object with no values in this property in class.
    The result in data of the table is 2.E239 when the correct value should be 4.

    The trigger is okay.

    In the XML mapping:
    <id name=”id” column=”ID” type=”java.lang.Integer”>
    <generator class=”sequence”>
    <param name=”sequence”>SPEDIDO</param>
    </generator>
    </id>

    i had already tried with Long type with no success.

    Any idea? 🙄

    Thanks, Raphael!

    #229546 Reply

    Riyad Kalla
    Member

    and i send the object with no values in this property in class.
    The result in data of the table is 2.E239 when the correct value should be 4.

    So the property value is null but when you persist the object you are saying that 2.E239 gets written in to the field?

    If the field “SPEDIDO” is auto incrementing, then you can juust change the generator type to “native” and let the DB set the ID instead of having hibernate do it, I prefer this approach as the DB is just as good it not better at setting it’s own row IDs than Hibernate.

    #230517 Reply

    rbandeira
    Member

    Ok! But if i want to use the sequence??? I dont want to write triggers in the database!! I would like to set the squence in the XML file and then let to hibernate to make the query with the “SPEDIDO.NEXTVAL()”…. 😕

    I really cant think a way to this crazy number appears instead of “4”.

    Maybe if i change the generator class from SEQUENCE to another type?

    Thanks. Raphael! 😆

    #230519 Reply

    Riyad Kalla
    Member

    Try it, see what happens… if you are still getting this crazy number then there is some flaky code somewhere doing this. Try “native” (but the field type in the DB needs to be autoincrement).

    #230616 Reply

    rbandeira
    Member

    I understood, but i would like to use without auto-increment. My manager here dont like to put triggers in the DB to do that.

    So, i must make with the sequence way…… please, help me!!!

    Thanks, Raphael!! [img 😯 ]” alt=””>

    #230618 Reply

    Riyad Kalla
    Member

    Autoincrement is not a trigger, it’s a field type flag.

    Regardless this is a Hibernate oddity, you are going to need to do some more investigation on your own before I can help, I have no idea what your server setup is like or what your project code looks like to help. This strange phantom number can be comming from anyone.

    As far as troubleshooting, you can try creating a new very simple project that creates a mapping to your DB and try and write some test cases to see if it still generates these phantom values.

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: Hibernate insert problem in field number

You must be logged in to post in the forum log in