English 中文(简体)
如何使用JPA/Hibernate确定综合主要钥匙的栏目
原标题:How to set the column order of a composite primary key using JPA/Hibernate

我对我综合主要钥匙的栏目排列有异议。 我的表格如下:

@Embeddable
public class MessageInfo implements Serializable {

    private byte loc;
    private long epochtime;

    @Column(name = "loc")
    public byte getLoc() {
        return loc;
    }    

    @Column(name = "epochtime")
    public long getEpochtime() {
        return epochtime;
    }
}

It is used in this mapping:

@MappedSuperclass
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class AbstractMessage implements Message {

    private MessageInfo info;
    private int blah;

    @EmbeddedId
    public MessageInfo getInfo() {
        return info;
    }
}

当I子级“摘要”以具体的“可计量类别”创建数据库和表格时,没有错误。 问题是,冷藏状态正在形成我所希望的相反顺序各栏的综合主要关键。

CREATE TABLE  `mydb`.`concrete_table` (
  `epochtime` bigint(20) NOT NULL,
  `loc` tinyint(4) NOT NULL,
  `blah` smallint(6) DEFAULT NULL,
  `foo` smallint(6) DEFAULT NULL,
  PRIMARY KEY (`epochtime`,`loc`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

我希望主要关键在于:

PRIMARY KEY (`loc`,`epochtime`)

自2006年以来 我知道,我将拥有最多10个休息室,但每个休息室都有许多时间。

任何帮助将受到赞赏=

最佳回答

我确实不认为有办法这样做。 我可以这样说,你就使用你制作的“彩虹”声明(改称有正确的次序),并手工操作。

在试验中,Hibernate做事。

问题回答

这样做是有办法的。 如何选择订购一套主要钥匙的栏目,按贵国界定的标名字母顺序排列。

因此,例如,如果您宣布这样的目标:

private byte loc;
private long epochtime;

你们现在就要:

(`epochtime`,`loc`)

但是,如果你重新命名为:

private byte aloc;
private long epochtime;

它将产生以下结果:

(`aloc`, `epochtime`)

以前就是如此。

我在希望我的分组指数符合具体顺序时发现了这一点。 我知道,这是令人不快的,但这是我能够找到的唯一办法,因此我不得不人工改变我的图象。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签