Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernateToolTask (hbm2hbmxml) doesn't generate index in hibernate-mapping from @org.hibernate.annotations.Index annotations
    primarykey
    data
    text
    <p>I am trying to generate hibernate-mapping from POJOs with hibernate annotations. Then I want to use liquibase to generate database schema. So I need indexes to be defined in my POJOs. </p> <p>Sample POJO:</p> <pre><code>@Entity public class A { @Id @GeneratedValue private Long id; @Index(name = "IDX_NAME") @ForeignKey(name="sd") private String name; } </code></pre> <p>But when I run HibernateToolTask in ant:</p> <pre><code>&lt;hibernateTool&gt; &lt;classpath&gt; &lt;path location="${path}"/&gt; &lt;/classpath&gt; &lt;annotationconfiguration configurationfile="src/hibernate.cfg.xml"/&gt; &lt;hbm2hbmxml destdir="${project.dir}"/&gt; &lt;hbm2ddl destdir="database/liquibase" export="false" outputfilename="update_${stamp}.sql" /&gt; &lt;/hibernateTool&gt; </code></pre> <p>I don't get any indexes in mapping:</p> <pre><code>&lt;class name="A" table="A"&gt; &lt;id name="id" type="java.lang.Long" access="field"&gt; &lt;column name="id" /&gt; &lt;generator class="native"&gt;&lt;/generator&gt; &lt;/id&gt; &lt;property name="name" type="java.lang.String" access="field"&gt; &lt;column name="name" /&gt; &lt;/property&gt; &lt;/class&gt; </code></pre> <p>At the same time, when I do hbm2ddl - 'create index' is generated:</p> <pre><code>create table A (id bigint not null auto_increment, name varchar(255), primary key (id)) type=InnoDB; create index IDX_NAME on A (name); </code></pre> <p>How can I make hibernate generate indexes in the mapping?</p> <p><strong>UPDATE:</strong></p> <p>I found out, that liquibase uses annotations to generate schema, so this part of problem is solved. I still have another one:</p> <p>I want to reverse engineer existing database to POJOs. POJOs are generated from mapping and mapping (generated using jdbcannotation-hbm2hbmxml) doesn't have any indexes. I believe this is essentially the same problem: hbm2hbmxml doesn't generate indexes.</p> <p><strong>UPDATE 2:</strong></p> <p>Why do I need that? I have an existing database schema. I used to change it and then reverse engineer POJOs. Now I want to work with POJOs and generate mapping and schema by annotations.</p> <p>So I'd like to have POJOs matching current database schema to move on with them. Apparently everything besides foreign key names and indexes is matching. But hbm2java doesn't generate @Index annotation., e.g.</p> <pre><code>&lt;hibernateTool&gt; &lt;jdbcconfiguration propertyfile="${build.dir}/etc/hibernate.properties" packagename="${doPackageName}"/&gt; &lt;hbm2java destdir="${destinationDir}" jdk5="true" ejb3="true"/&gt; &lt;hbm2ddl destdir="${destinationDir}" export="false" outputfilename="update_${stamp}.sql" /&gt; &lt;/hibernateTool&gt; </code></pre> <p>This task generates indexes in ddl and doesn't generate indexes in POJOs.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload