PostgreSQL/Oracle Table
ͨ³£ÎÒ們ÔÚ½¨Á¢ PostgreSQL/Oracle 資ÁÏ庫µÄ時ºò, Èç¹ûҪʹÓà MySQL/MS-SQL identity À×ͬµÄ¹¦ÄÜ, ¾ÍÊÇÒª採Óà Sequence 來½¨Á¢, ¶ø為ÁËÿһ個 Table ¶¼ÓÐ獨Á¢µÄÐò號產ÉúÆ÷, ÎÒ們會½¨Á¢個別µÄ sequence.
ÀýÈç (PostgreSQL sample):
CREATE SEQUENCE "student_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1;
create table student (
id bigint PRIMARY KEY DEFAULT NEXTVAL('student_seq'),
name character varying(50),
studentno character varying(50)
)
當ÎÒ們ʹÓûù±¾µÄ SQL command ¾ÍÊÇ
Insert into student ( name, studentno ) values ( 'jini', '890099' )
進ÐÐ Insert µÄ動×÷, Ëû×ÔÈ»會幫ÎÒÈ¡µÃ nextval of student_seq 進ÐÐ Insert.
ÄÇ麼, ÔÚ Hibernate annotation 標準µÄ×÷·¨, ¾ÍÊÇ
@Entity
@SequenceGeneratorr(name = "TheSEQ", allocationSize = 1, initialValue = 0, sequenceName = "student_seq")
public class Student implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE
, generator = "TheSEQ")
private Long id;
// other attributes, getters and setters
}
這樣, ÎÒÿһ個 @Id ¶¼µÃ»¨時間寫Ö¸¶¨µÄ sequence name,
雖È»沒ÓÐʲ麼²»ºÃ, µ«ÊÇÎÒ們¿ÉÒÔÀûÓà [tablename]_seq µÄÔ則¶¨義 seq, ¾Í應該¿ÉÒÔ͸過 Dialect 來決¶¨ÎÒµÄ IdGenerator µÄ·½Ê½
ËùÒÔÎÒÏ£Íûδ來µÄ³Ìʽ碼Ö»ÓÐÒÔÏÂËùÁÐ, ÀûÓà AUTO ¶ø·Ç SEQUENCE generated type.
@Entity
public class Student implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private
Ïà¹ØÎĵµ£º
ÔÚ¿ªÊ¼Ö®Ç°£¬ÐèÒª¼òµ¥ËµÃ÷һϣ¬Ä¿Ç°¹«Ë¾Óм¸¸öÏîÄ¿¶¼²ÉÓÃOracle×÷ΪÊý¾Ý¿âƽ̨£¬²¢ÇÒÓеÄÏîĿʹÓõ½ÁËOracleµÄÊý¾Ý¿â¸´ÖƼ¼Êõ£¬ÆäÖÐÒ²Óöµ½ÁËһЩÎÊÌ⣬Òò´ËÔÚÕâÀÎÒ¶ÔOracleµÄ¸´ÖƼ¼Êõ̸һÏÂÎÒ¸öÈ˵ÄÀí½â£¬Ï£ÍûÄܹ»¶Ô²ÉÓÃOracleÊý¾Ý¿âµÄÏîÄ¿×éÓÐËù°ïÖú¡£ÆäÖÐÔÚÎÄÖÐʹÓõ½µÄSQL½Å±¾¶¼ÊǾ¹ý¼ìÑé¿ÉÒÔÔËÐеġ£
¡¡¡¡Ê ......
ÏîÄ¿¿ª·¢ÖУ¬ÐèÒªÔ¶³Ì±¸·ÝÊý¾Ý¿â£¬ÒÔÏÂΪC#Ô¶³Ì±¸·ÝÊý¾Ý¿âµÄ´úÂë
/// <summary>
/// Êý¾Ý¿â±¸·Ý
/// </summary>
/// <param name="fileName">dmpÎļþÃû³Æ</param>
/// <param name="logFileName">logÎļþÃû³Æ</param>
/// <re ......
--1:ÎÞORDER BYÅÅÐòµÄд·¨¡£(ЧÂÊ×î¸ß)
--(¾¹ý²âÊÔ£¬´Ë·½·¨³É±¾×îµÍ£¬Ö»Ç¶Ì×Ò»²ã£¬ËÙ¶È×î¿ì£¡¼´Ê¹²éѯµÄÊý¾ÝÁ¿ÔÙ´ó£¬Ò²¼¸ºõ²»ÊÜÓ°Ï죬ËÙ¶ÈÒÀÈ»£¡)
SELECT *
from (Select ROWNUM AS ROWNO, T.*
from k_task T &s ......
±¾ÊµÀýÒÑÍêȫͨ¹ý²âÊÔ,µ¥Ïò,ÓÖÏòͬ²½¶¼¿ÉʹÓÃ.
--Ãû´Ê˵Ã÷£ºÔ´——±»Í¬²½µÄÊý¾Ý¿â
Ä¿µÄ——Ҫͬ²½µ½µÄÊý¾Ý¿â
ǰ6²½±ØÐëÖ´ÐÐ,µÚ6ÒÔºóÊÇһЩ¸¨ÖúÐÅÏ¢.
--1¡¢ÔÚÄ¿µÄÊý¾Ý¿âÉÏ£¬´´½¨dblink
drop public database link dblink_or ......