1

Is it possible to add a boolean field into an array table in hibernate? I know this goes against the theoretical structure of an array, but maybe there's another collection type usable with hibernate that can do this?

i.e. (for illustration purposes)

idPerson      idAddress    indx      currentlyResident
    2             32        0               1

where idPerson is key
indx is index
idAddress is many-to-many

Thanks!

edit: This boolean value needs to be saved as part of the cross-reference table

Hibernate Mapping is very standard, just need to get an extra property in there!

<array name="addresses" table="personAddressCrossReference" cascade="all">
   <key column="idPerson" />
   <index column="indx" />
   <many-to-many column="idAddress" class="etc." />
</array>
1
  • Please show your hibernate-mapping. Commented Apr 3, 2012 at 10:50

1 Answer 1

2

Yes you can. Add a attribute to your class and set it transient:

http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/#entity-mapping-property

you have to calculate and set the value yourself. You may use the @PostConstruct annotation.

Sign up to request clarification or add additional context in comments.

2 Comments

Does making it transient not mean that it will only be valid for the lifetime of the instance? This value needs to be saved as part of the cross-reference table. Also, in trying to think of where the getter and setter should be placed, would it be in the Person or Address object?
Ohh, then I misunderstood your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.