# How can i force hibernate to save ipBytes as BINARY type?

**URL:** https://discourse.hibernate.org/t/how-can-i-force-hibernate-to-save-ipbytes-as-binary-type/2105
**Category:** Hibernate OGM
**Created:** [January 21, 2019, 9:30am UTC](https://discourse.hibernate.org/t/how-can-i-force-hibernate-to-save-ipbytes-as-binary-type/2105 "2019-01-21T09:30:30Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Lylyhannah](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Lylyhannah](https://discourse.hibernate.org/u/Lylyhannah)
#### Post date: [January 21, 2019, 9:30am UTC](https://discourse.hibernate.org/t/how-can-i-force-hibernate-to-save-ipbytes-as-binary-type/2105/1 "2019-01-21T09:30:30Z")

</div>

I used hibernate 5.2.12 with mysql database.

I have following class (simplified):

```auto
@Embeddable
@Access( AccessType.FIELD )
public class IpAddress implements Serializable,Comparable<IpAddress>{

    @Column(name = "ip_address", length = 17)
    @Type(type = "org.hibernate.type.BinaryType")
    private byte[] ipBytes;
}

```

I want that ipBytes to be mapped to BINARY(17) mysql type,and i try to use @Type annotation, but there is no effect, hibernate map ipBytes to TINYBLOB.

I tried to use columnDefinition = “BINARY(17)”, and it work’s, but i don’t know is it safe to use, and also it database dependent.

Also tried UUIDBinaryType and hibenrnate map ipBytes right(to BINARY(17)), but when i try to insert there is an exception, because uuid must be 16 bytes length value.

How can i force hibernate to save ipBytes as BINARY type?

---

<div class="post-metadata">

### Author: ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)
#### Post date: [January 21, 2019, 9:34am UTC](https://discourse.hibernate.org/t/how-can-i-force-hibernate-to-save-ipbytes-as-binary-type/2105/2 "2019-01-21T09:34:59Z")

</div>

Check out this answer:

> [@How to map byte\[\] to jdbc BINARY type?](https://discourse.hibernate.org/t/how-to-map-byte-to-jdbc-binary-type/222/2):
>
> It’s actually very simple. Since version [2.10.1](https://github.com/vladmihalcea/hibernate-types/issues/23), you can use the MySQLBinaryType from the [Hibernate Types project](https://github.com/vladmihalcea/hibernate-types), so your mapping looks like this: @Entity @TypeDef( typeClass = MySQLBinaryType.class, defaultForType = byte[].class ) public class Post { @Id @GeneratedValue private Long id; private String title; @Column private byte[] image; ... } Here you can see [an example on GitHub](https://github.com/vladmihalcea/hibernate-types/blob/f94b2e412e3d048bc34774e4180c29a62a486849/hibernate-types-52/src/test/java/com/vladmihalcea/hibernate/type/binary/MySQLBinaryTypeTest.java) that works like a charm.
