1

I have structure of inherited entities classes with strategy JOINED. Total amount of fields of final (leaf) entity class is more than 3000. Can Hibernate operate with so wide entity autonomous? Of course I know about max column count limit on RDBMS level. Does this limit matter on work with jpa?

  • As jpa entity is a java class. I guess [this question](https://stackoverflow.com/questions/48011697/what-is-the-maximum-number-of-fields-a-java-class-can-have) will address yours. – SternK Jan 20 '21 at 22:54
  • Okay. The top limit of Java possibility is known. But what about JPA? I suppose it must be significant lower. – Alexander Fedyukov Jan 21 '21 at 04:43

2 Answers2

1
  1. As it stated in the hibernate documentation:

The joined table inheritance polymorphic queries can use several JOINS which might affect performance when fetching a large number of entities.

  1. I do not know what database you use, so just for reference:
  • Oracle table can hold up to 1000 columns (see this)
  • PostgreSQL table can hold up to 1600 columns (see this)
  • MySQL table can hold up to 4096 columns (see this)
  1. As it was answered here:

The number of fields that may be declared by a class or interface is limited to 65535 by the size of the fields_count item of the ClassFile structure (§4.1)

So, IMHO, you rather will face with java.lang.OutOfMemoryError exception or performance problem than limitation due fields count in entity.

SternK
  • 11,649
  • 22
  • 32
  • 46
  • But can Hibernate work around the DB limitations? – Alexander Fedyukov Jan 25 '21 at 06:57
  • Yes, hibernate does it for some **common** cases. For example hibernate provide [the table identifier generator](https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#identifiers-generators-table) and it can be useful for databases that do not support sequences. But your case is very specific. And as for me your difficulty rather indicate that you use wrong approach/technology for your problem. – SternK Jan 25 '21 at 09:18
0

I've done light R&D work with this task and ready to explain results.

  1. Hibernate allows you operate with wide entities. You can build class hierarchy with strategy joined and spread required fields among classes of hierarchy.
  2. After that you can feel free to fill and persist entities in ordinary way
  3. But! You can't read whole entity by one query: DB has limit of maximum column count per tuple in ResultSet.