0

I want to use Hibernate to map a class to a database. The class contains values from different sensors. It is important that the class may be changed at runtime(new sensor added...). Changes of the variables are estimated to be quite rare. Can I use Hibernate in this case?

I thought about using a Hashmap with String Keys representing the Column Header and the Sensorname. The mapped value would be the current Double sensor value.

An example table could look like this:

Table Station1
-----------------------------------------------------
+ Timestamp           + Sensor1 + Sensor2 + Sensor3 +
-----------------------------------------------------
+ 2012-10-10 12:12:12 + 12.1212 + 23.2323 + 34.3434 +
+ 2012-10-10 12:12:13 + 12.1213 + 23.2323 + 54.3434 +
-----------------------------------------------------

I would be happy if someone could give me feedback if its possible and maybe some directions for me to search further.

4
  • Why do you need to edit the class at runtime? Why not use a java.util.ArrayList<YourClass> and add to the List instead? The software can read from the List and display its output from additional sensors Commented Oct 21, 2012 at 17:42
  • stackoverflow.com/questions/483981/… Commented Oct 21, 2012 at 17:42
  • It looks like you should normalize your schema, and have a OneToMany association between Station and Sensor. Commented Oct 21, 2012 at 17:45
  • hibernate can't do what you're looking for. it's designed to operation on a static schema. In this case, you need to move the sensors out to a "vertical" table which has a sensor id and a sensor value, and map the readings in as OneToMany relationship. Commented Oct 21, 2012 at 19:35

0

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.