I've noticed that if I use the persistence API to create a database table the order of the table columns is not the same as in the persistence data-class. Is it possible to keep the field order in a data-class to a database table?

asked 24.04.2014 at 10:29

Nikel%20Weis's gravatar image

Nikel Weis
accept rate: 57%

Another solution is to create your database in SQL first and then create your persistence data clases accordingly to the SQL-Database. So it is possible to apply a certain order.


answered 06.06.2014 at 08:48

Nikel%20Weis's gravatar image

Nikel Weis
accept rate: 57%

You still need to use ORDER BY for certain queries because it is not guaranteed that your query result is in the very order of your database. So you need to manually ensure the order of your results, else you get a bug that is hard to pin down.

(06.06.2014 at 09:59) Daniel Oechslin Daniel%20Oechslin's gravatar image

I think there was a misunderstanding in my question. It is not the target to have the object in a certain order. The objective was that the columns within the database are in a certain order.

(06.06.2014 at 13:03) Nikel Weis Nikel%20Weis's gravatar image

The only solution I can think of is if you sort your data-class alphabetically and you add the ORDER BY attribute to your database query.


answered 02.06.2014 at 12:47

Daniel%20Oechslin's gravatar image

Daniel Oechslin
accept rate: 39%

Thanks for your reply. That would be a possibility if the database should only be created via persistence - so +1 for that. But it is also possible to do it the other way around. :)

(06.06.2014 at 08:49) Nikel Weis Nikel%20Weis's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 24.04.2014 at 10:29

Seen: 1,575 times

Last updated: 06.06.2014 at 13:03