How to create a table column in a specific order in sleep mode?

There is a duplicate for my question , but it has not yet been answered. I start hibernation by creating a table automatically from an object in SQL Server using the property

<property name="hibernate.hbm2ddl.auto">create</property>

it looks like the column order of the table is wrong, and that was not a problem for me until I used a compound key. Now the problem is that the column order is not the same as the business object. Here is the business object you created

@Entity
public class SalesEstimateDtl implements Serializable {
@Id
private Long LedSalesEstID;
@Id
private Integer LedSalesEstRowNo;

and here is the generated request

CREATE TABLE [dbo].[SalesEstimateDtl](
             [LedSalesEstRowNo] [int] NOT NULL,
             [LedSalesEstID] [numeric](19, 0) NOT NULL,
             PRIMARY KEY CLUSTERED 
             (
               [LedSalesEstRowNo] ASC,
               [LedSalesEstID] ASC
             ) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

How can I change the order of LedSalesEstRowNo using LedSalesEstID?

+4
source share
3 answers

, , , , . SELECT * .

, Hibernate, , , Hibernate. .

, Hibernate hbm2ddl . , Hibernate, ALTER .

, !

+1

@EmbeddedId

 @Entity
    class Student{
        @EmbeddedId
        StudentInfo id;

        String Name;
        String Class;
        Integer RollNo;
    }

    @Embeddable
    class StudentInfo implements serializable {
        Integer StudentID;
        Integer StudentRowNo;
    }
+3

Use the Below property inside the Hibernate configuration file

<property name="hibernate.hbm2ddl.auto">showShemaUpdate</property>

Then use the code below before creating the SessionFactory.   String file = "SqlSchema.sql"; SchemaUpdate update = new SchemaUpdate(configuration); update.setOutputFile(file); update.execute(false, false);

It will create the SqlSchema.sql file in one place containing all the DDL queries. Change them in any order.

0
source

Source: https://habr.com/ru/post/1688195/


All Articles