锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 銆銆緇欐潵鑷?0.163.225.87鐨勭敤鎴穓oe鍒嗛厤鍙鏁版嵁搴搗tdc鐨別mployee琛ㄨ繘琛宻elect,insert,update,delete,create,drop絳夋搷浣滅殑鏉冮檺錛屽茍璁懼畾鍙d護涓?23銆?/p>
瑕侀噸鍚竴嬈YSQL鎵嶈兘浣挎湰鍦扮敤鎴峰瘑鐮佺敓鏁堬細 /usr/local/mysql/support-files/mysql.server restart
]]>
鍏跺畠鍙傛暟鐨勪緥瀛愶細
grant select,insert,update,delete,create,drop on vtdc.employee to joe@10.163.225.87 identified by '123';
]]>
]]>
]]>
]]>
Join鐢ㄦ硶:
涓昏鏈塈nner Join 鍙?Outer Join:
鏈甯哥敤鐨勶紙榛樿鏄疘nner錛夛細
Select <瑕侀夋嫨鐨勫瓧孌?gt; From <涓昏璧勬枡琛?gt;
銆銆<Join 鏂瑰紡> <嬈¤璧勬枡琛?gt; [On <Join 瑙勫垯>]
Inner Join 鐨勪富瑕佺簿紲炲氨鏄?exclusive , 鍙畠鍋氭帓浠栨у惂! 灝辨槸璁?Join 瑙勫垯涓嶇浉絎︾殑璧勬枡灝變細琚帓闄ゆ帀, 璀璁插湪 Product 涓湁涓欏逛駭鍝佺殑渚涜揣鍟嗕唬鐮?(SupplierId), 娌℃湁鍑虹幇鍦?Suppliers 璧勬枡琛ㄤ腑, 閭d箞榪欑瑪璁板綍渚夸細琚帓闄ゆ帀
Outer Join:
Select <瑕佹煡璇㈢殑瀛楁> From <Left 璧勬枡琛?gt;
銆銆<Left | Right> [Outer] Join <Right 璧勬枡琛?gt; On <Join 瑙勫垯>
璇硶涓殑 Outer 鏄彲浠ョ渷鐣ョ殑, 渚嬪浣犲彲浠ョ敤 Left Join 鎴栨槸 Right Join, 鍦ㄦ湰璐ㄤ笂, Outer Join 鏄?inclusive, 鍙畠鍋氬寘瀹規у惂! 涓嶅悓浜?Inner Join 鐨勬帓浠栨? 鍥犳鍦?Left Outer Join 鐨勬煡璇㈢粨鏋滀細鍖呭惈鎵鏈?Left 璧勬枡琛ㄧ殑璧勬枡, 棰犲掕繃鏉ヨ, Right Outer Join 鐨勬煡璇㈠氨浼氬寘鍚墍鏈?Right 璧勬枡琛ㄧ殑璧勬枡
鍙﹀錛岃繕鏈夊叏澶栬仈錛?
FULL JOIN 鎴?FULL OUTER JOIN
瀹屾暣澶栭儴鑱旀帴榪斿洖宸﹁〃鍜屽彸琛ㄤ腑鐨勬墍鏈夎銆傚綋鏌愯鍦ㄥ彟涓涓〃涓病鏈夊尮閰嶈鏃訛紝鍒欏彟涓涓〃鐨勯夋嫨鍒楄〃鍒楀寘鍚┖鍊箋傚鏋滆〃涔嬮棿鏈夊尮閰嶈錛屽垯鏁翠釜緇撴灉闆嗚鍖呭惈鍩鴻〃鐨勬暟鎹箋?
浠ュ強錛?
浜ゅ弶鑱旀帴榪斿洖宸﹁〃涓殑鎵鏈夎錛屽乏琛ㄤ腑鐨勬瘡涓琛屼笌鍙寵〃涓殑鎵鏈夎緇勫悎銆備氦鍙夎仈鎺ヤ篃縐頒綔絎涘崱灝旂Н銆?
娌℃湁 WHERE 瀛愬彞鐨勪氦鍙夎仈鎺ュ皢浜х敓鑱旀帴鎵娑夊強鐨勮〃鐨勭瑳鍗″皵縐傜涓涓〃鐨勮鏁頒箻浠ョ浜屼釜琛ㄧ殑琛屾暟絳変簬絎涘崱灝旂Н緇撴灉闆嗙殑澶у皬銆備篃灝辨槸璇村湪娌℃湁 WHERE 瀛愬彞鐨勬儏鍐典笅錛岃嫢琛?A 鏈?3 琛岃褰曪紝琛?B 鏈?6 琛岃褰?: 錛?
SELECT A.*,B.* FROM 琛ˋ CROSS JOIN 琛˙
閭d互涓婅鍙ヤ細榪斿洖 18 琛岃褰曘?
Fetch:
鍦ㄦ垜浠煡璇arent瀵硅薄鐨勬椂鍊欙紝榛樿鍙湁Parent鐨勫唴瀹癸紝騫朵笉鍖呭惈childs鐨勪俊鎭紝濡傛灉鍦≒arent.hbm.xml閲岃緗甽azy="false"鐨勮瘽鎵嶅悓鏃跺彇鍑哄叧鑱旂殑鎵鏈塩hilds鍐呭.
闂鏄垜鏃㈡兂瑕乭ibernate榛樿鐨勬ц兘鍙堟兂瑕佷復鏃剁殑鐏墊椿鎬ц鎬庝箞鍔烇紵 榪欏氨鏄痜etch鐨勫姛鑳姐傛垜浠彲浠ユ妸fetch涓巐azy="true"鐨勫叧緋葷被姣斾負浜嬪姟褰撲腑鐨勭紪紼嬪紡浜嬪姟涓庡0鏄庡紡浜嬪姟,涓嶅お鍑嗙‘錛屼絾鏄ぇ姒傛槸榪欎釜鎰忔濄?br>鎬誨鹼紝fetch灝辨槸鍦ㄤ唬鐮佽繖涓灞傜粰浣犱竴涓富鍔ㄦ姄鍙栧緱鏈轟細.
Parent parent = (Parent)hibernateTemplate.execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query q = session.createQuery(
"from Parent as parent "+
" left outer join fetch parent.childs " +
" where parent.id = :id"
);
q.setParameter("id",new Long(15));
return (Parent)q.uniqueResult();
}
});
Assert.assertTrue(parent.getChilds().size() > 0);
浣犲彲浠ュ湪lazy="true"鐨勬儏鍐典笅鎶奻etch鍘繪帀錛屽氨浼氭姤寮傚父. 褰撶劧錛屽鏋渓azy="false"灝變笉闇瑕乫etch浜?
HQL涓浜涚壒鑹叉柟娉曪細
in and between may be used as follows:
from DomesticCat cat where cat.name between 'A' and 'B'
from DomesticCat cat where cat.name in ( 'Foo', 'Bar', 'Baz' )
and the negated forms may be written
from DomesticCat cat where cat.name not between 'A' and 'B'
from DomesticCat cat where cat.name not in ( 'Foo', 'Bar', 'Baz' )
Likewise, is null and is not null may be used to test for null values.
Booleans may be easily used in expressions by declaring HQL query substitutions in Hibernate configuration:
<property name="hibernate.query.substitutions">true 1, false 0</property>
This will replace the keywords true and false with the literals 1 and 0 in the translated SQL from this HQL:
from Cat cat where cat.alive = true
You may test the size of a collection with the special property size, or the special size() function.
from Cat cat where cat.kittens.size > 0
from Cat cat where size(cat.kittens) > 0
For indexed collections, you may refer to the minimum and maximum indices using minindex and maxindex functions. Similarly, you may refer to the minimum and maximum elements of a collection of basic type using the minelement and maxelement functions.
from Calendar cal where maxelement(cal.holidays) > current_date
from Order order where maxindex(order.items) > 100
from Order order where minelement(order.items) > 10000
The SQL functions any, some, all, exists, in are supported when passed the element or index set of a collection (elements and indices functions) or the result of a subquery (see below).
select mother from Cat as mother, Cat as kit where kit in elements(foo.kittens)
select p from NameList list, Person p where p.name = some elements(list.names)
from Cat cat where exists elements(cat.kittens)
from Player p where 3 > all elements(p.scores)
from Show show where 'fizard' in indices(show.acts)
Note that these constructs - size, elements, indices, minindex, maxindex, minelement, maxelement - may only be used in the where clause in Hibernate3.
Elements of indexed collections (arrays, lists, maps) may be referred to by index (in a where clause only):
from Order order where order.items[0].id = 1234
select person from Person person, Calendar calendar where calendar.holidays['national day'] = person.birthDay and person.nationality.calendar = calendar
select item from Item item, Order order where order.items[ order.deliveredItemIndices[0] ] = item and order.id = 11
select item from Item item, Order order where order.items[ maxindex(order.items) ] = item and order.id = 11
The expression inside [] may even be an arithmetic expression.
select item from Item item, Order order where order.items[ size(order.items) - 1 ] = item
HQL also provides the built-in index() function, for elements of a one-to-many association or collection of values.
select item, index(item) from Order order join order.items item where index(item) < 5
Scalar SQL functions supported by the underlying database may be used
from DomesticCat cat where upper(cat.name) like 'FRI%'